Ленивость в окамле
Aug. 13th, 2013 04:17 pmutop[0]> open Core.Std;; utop[1]> let a = lazy (printf "A\n"; 0);; val a : int lazy_t = <lazy> utop[2]> let b (a : int) = lazy (printf "B\n"; 0);; val b : int -> int lazy_t = <fun> utop[3]> Lazy.force Lazy.(a >>= b);; A B - : int = 0
Ну ё-моё...
no subject
Date: 2013-08-13 04:54 pm (UTC)type 'a lazy_inside = Ready of 'a | Postponed of (() -> 'a) type 'a lazy_t = 'a lazy_inside ref lazy f = ref (Postponed f) force r = match !r with | Ready x -> x | Postponed f -> let x = f () in r := Ready x; x (>>=) r f = lazy (fun _ -> force (f (force x)))no subject
Date: 2013-08-13 05:08 pm (UTC)