Skip to content

Instantly share code, notes, and snippets.

@raichoo
Created March 30, 2014 11:14
Show Gist options
  • Save raichoo/9871253 to your computer and use it in GitHub Desktop.
Save raichoo/9871253 to your computer and use it in GitHub Desktop.
Problem with Lazyness
-- Only works in the REPL, compiled code explodes with SIGABRT
-- or SIGSEGV
-- Does not terminate
nats : Stream Nat
nats = 0 :: map (+1) nats
mapi : List a -> List (Nat, a)
mapi xs = mapi' nats xs
where mapi' : Stream Nat -> List a -> List (Nat, a)
mapi' _ [] = []
mapi' (n :: ns) (x :: xs) = (n, x) :: mapi' ns xs
{-
-- Works
nats : Lazy (List Nat)
nats = 0 :: map (+1) nats
mapi : List a -> List (Nat, a)
mapi xs = mapi' nats xs
where mapi' : Lazy (List Nat) -> List a -> List (Nat, a)
mapi' _ [] = []
mapi' (n :: ns) (x :: xs) = (n, x) :: mapi' ns xs
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment