update lecture 08 notes

This commit is contained in:
SowinskiBraeden committed 2026-03-11 19:18:02 -07:00
1 parent 9b62c01175
commit edd9a45302
3 files changed
+68 -14

No files matched your search

+14 -4
View File
@@ -1,13 +1,17 @@
type 'a lazystream = Cons of 'a * 'a lazystream Lazy.t
let hd (Cons (h, _)) = h;;
let tl (Cons (_, t)) = Lazy.force t;;
let hd (Cons (h, _)) = h
let tl (Cons (_, t)) = Lazy.force t
let rec from n = Cons (n, lazy (from (n + 1)));;
let rec from n = Cons (n, lazy (from (n + 1)))
let rec take n (Cons (h, t)) =
if n <= 0 then []
else h :: take (n - 1) (Lazy.force t);;
else h :: take (n - 1) (Lazy.force t)
let rec drop n (Cons (h, t) as s) =
if n <= 0 then s
else drop (n - 1) (Lazy.force t)
let rec map f (Cons (h, t)) =
Cons (f h, lazy (map f (Lazy.force t)))
@@ -17,3 +21,9 @@ let rec map2 f (Cons (h1, t1)) (Cons (h2, t2)) =
let rec fibs =
Cons (0, lazy (Cons (1, lazy (map2 (+) fibs (tl fibs)))))
let rec unfold f x =
let (v, x') = f x in
Cons (v, lazy (unfold f x'))
let fibs' = unfold (fun (a, b) -> (a, (b, a + b))) (0, 1)