Skip to content

Instantly share code, notes, and snippets.

@ghulette
Created March 1, 2018 01:23
Show Gist options
  • Save ghulette/b4e7c1bcdd350691806a802bdad1c51b to your computer and use it in GitHub Desktop.
Save ghulette/b4e7c1bcdd350691806a802bdad1c51b to your computer and use it in GitHub Desktop.
(* nats = 0 :: List.map (fun x -> x+1) nats *)
type 'a lazylist =
| Nil
| Cons of 'a * (unit -> 'a lazylist)
let rec take n l =
match (n,l) with
| 0,_ -> []
| _,Nil -> []
| _,Cons (x,l) -> x :: take (n-1) (l ())
let rec map f = function
| Nil -> Nil
| Cons (x,l) -> Cons (f x, fun () -> map f (l ()))
let rec nats = Cons (1, fun () -> map succ nats)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment