- Domain: Parallelism
- Threads (but not the usual kind??)
- Concurrency: Effect handlers
- Overlapped execution. Yield-restart kind of thing.
Effect handlers
No primitives for concurrency till Ocaml5.
- 3rd party libs: Lwt and Async
- Not primitive. Essentially, syntactic sugar.
- Monadic syntax, but doesn't obey monadic laws ??
- Less readable errors. No backtrace. No exceptions.
Can think of effect handlers as 'first-class, restartable exceptions'
(* When [E] is performed, we will get a value of type [string] *)
effect E: string
(* A computation. Like a thunk *)
let comp () =
print_string "0: start";
print_string (perform E);
print_string "3: end";
let main () =
try
comp ()
(* Effect handler. [k] is a delimited continuation *)
with effect E k ->
print_string "1: EH start";
continue k "2: EH cont";
print_string "4: EH end";Here control goes like:
- main
- comp: start
- E k: EH start
- comp: EH cont, end
- E k: EH end