Skip to content

Instantly share code, notes, and snippets.

@camilopayan
Created March 7, 2010 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camilopayan/324639 to your computer and use it in GitHub Desktop.
Save camilopayan/324639 to your computer and use it in GitHub Desktop.
type 'a stream = Cons of 'a * (unit -> 'a stream)
let rec upfrom n = Cons(n, fun () -> upfrom(n+1))
let t = upfrom 0
let rec take n (Cons(x,xsf)) = if n=0 then [] else x::(take (n-1) (xsf()))
(*Here's the map function, the rest is just to set it up or demonstrate it*)
let rec map f (Cons(x,xsf)) = Cons( (f x), fun() -> map f (xsf()))
take 10 (map (fun x -> x+x) t);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment