let rec x = x;; let rec f x = f x;; f 0;; let rec f x = if f = 0 then 0 else f x;; let rec f x = if x = 0 then 0 else f x;; f 0;; f 2;; List.hd (f 0 :: f 1 :: []);; let rec from n = n :: (from (n + 1));; from 5;; let 'a llist = Nil | Cons of ('a * (unit -> 'a llist));; type 'a llist = Nil | Cons of ('a * (unit -> 'a llist));; let hd = function Nil -> failwith "nil" | Cons (x, _) -> x;; let tl = function Nil -> failwith "nil" | Cons (_, t) -> t;; let tl = function Nil -> failwith "nil" | Cons (_, t) -> t ();; let rec to_list n xs = if n < 1 then [] else match xs with Nil -> [] | Cons (x, xs) -> x :: (to_list (n - 1) xs);; let rec to_list n xs = if n < 1 then [] else match xs with Nil -> [] | Cons (x, xs) -> x :: (to_list (n - 1) (xs ()));; to_list 5 (from 0);; let rec from n = Cons (n, fun () -> from (n + 1));; to_list 5 (from 0);; to_list 500 (from 8);; type 'a cell = Nil | Cons of 'a * 'a llist and 'a llist = unit -> 'a cell;; let tl xs = match xs () with Nil -> failwith "nil" | Cons (_, xs) -> xs;; let rec zipwith f xs ys = fun () -> match (xs (), ys ()) with (Cons (x, xs), Cons (y, ys)) -> Cons (f x y, zipwith f xs ys) | _ -> Nil;; let rec from n = fun () -> Cons (n, from (n + 1));; zipwith (+) (from 0) (from 1);; (zipwith (+) (from 0) (from 1)) ();; tl (zipwith (+) (from 0) (from 1)) ;; (tl (zipwith (+) (from 0) (from 1))) () ;; let rec fibs = fun () -> Cons (0, fun () -> Cons (1, zipwith (+) fibs (tl fibs)));; fibs ();; tl fibs;; (tl fibs) ();; ((tl (tl fibs)) ();; ((tl (tl fibs))) ();; ((tl (tl (tl fibs)))) ();; (tl (tl (tl (tl fibs)))) ();; (tl (tl (tl (tl (tl fibs))))) ();; let rec to_list n xs = if n < 1 then [] else match xs () with Nil -> [] | Cons (x, t) -> x :: to_list (n-1) t;; to_list 5 fibs;; to_list 15 fibs;; to_list 20 fibs;; to_list 30 fibs;; to_list 32 fibs;; let e = lazy (print_string "bla");; Lazy.force e;; primes;; to_list 1000 primes;; List.rev (to_list 1000 primes);; List.nth 1000 (to_list 1000 primes);; List.nth (to_list 1000 primes) 1000;; List.nth (to_list 1000 primes) 999;;