Snippets

orbitzN gadt

Created by orbitzN last modified
type t = Exec : (('a -> unit) * 'a) -> t
;;

let rec consume_all q =
  let Exec (f, v) = Queue.pop q in
  f v;
  consume_all q
;;

let consume q =
  try
    consume_all q
  with
    | Queue.Empty ->
      ()
;;

let main () =
  let q : t Queue.t = Queue.create () in
  Queue.add (Exec (Printf.printf "%d\n", 5)) q;
  Queue.add (Exec (Printf.printf "%c\n", 'c')) q;
  consume q
;;

(*
# main ();;
5
c
*)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.