migmit: (Default)
[personal profile] migmit
utop[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

Ну ё-моё...

Date: 2013-08-13 04:54 pm (UTC)
From: [identity profile] migmit.livejournal.com
Потому что цитировать надо полностью. У меня сейчас под рукой компилятора нет, а ssh-ить лень, но будет как-то так:
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)))

Date: 2013-08-13 05:08 pm (UTC)
From: [identity profile] thedeemon.livejournal.com
Да, так ок.