move kitchen-sink demo into a separate directory

This commit is contained in:
Fabian Jakobs 2011-10-13 11:22:19 +02:00
commit 606963f424
39 changed files with 47 additions and 49 deletions

View file

@ -0,0 +1,18 @@
(*
* Example of early return implementation taken from
* http://ocaml.janestreet.com/?q=node/91
*)
let with_return (type t) (f : _ -> t) =
let module M =
struct exception Return of t end
in
let return = { return = (fun x -> raise (M.Return x)); } in
try f return with M.Return x -> x
(* Function that uses the 'early return' functionality provided by `with_return` *)
let sum_until_first_negative list =
with_return (fun r ->
List.fold list ~init:0 ~f:(fun acc x ->
if x >= 0 then acc + x else r.return acc))