Created
March 1, 2018 01:23
-
-
Save ghulette/b4e7c1bcdd350691806a802bdad1c51b 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
(* 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