Skip to content

Commit

Permalink
Deprecate cycle, repeat, and iterate
Browse files Browse the repository at this point in the history
Deprecate `Data.List.Linear.{cycle,repeat,iterate}`. 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 571a807
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Data/List/Linear.hs
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,17 @@ or = foldl' (||) False
-- # Building Lists
--------------------------------------------------

{-# DEPRECATED iterate "The result cannot be consumed linearly, so this function is not useful." #-}
iterate :: (Dupable a) => (a %1 -> a) -> a %1 -> [a]
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 571a807

Please sign in to comment.