Created
March 7, 2010 21:25
-
-
Save camilopayan/324639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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