Skip to content

Commit

Permalink
Deprecate cycle and repeat
Browse files Browse the repository at this point in the history
Deprecate `Data.List.Linear.cycle` and `Data.List.Linear.repeat`.
Infinite results cannot be consumed linearly, so they are not really
useful in a linear context. They could be consumed by a program that
exits via an exception, but I don't think that's something that should
really be supported.

Begins to address tweag#453
  • Loading branch information
treeowl committed Jun 12, 2023
1 parent 5a13fb6 commit db7cdb7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Data/List/Linear.hs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,11 @@ iterate f a =
dup2 a & \(a', a'') ->
a' : iterate f (f a'')

{-# DEPRECATED repeat "The result cannot be consumed linearly, so this function is not useful." #-}
repeat :: (Dupable a) => a %1 -> [a]
repeat = iterate id

{-# DEPRECATED cycle "The result cannot be consumed linearly, so this function is not useful." #-}
cycle :: (HasCallStack, Dupable a) => [a] %1 -> [a]
cycle [] = Prelude.error "cycle: empty list"
cycle xs = dup2 xs & \(xs', xs'') -> xs' ++ cycle xs''
Expand Down

0 comments on commit db7cdb7

Please sign in to comment.