Skip to content

Instantly share code, notes, and snippets.

@hakuch
Last active February 26, 2017 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakuch/484ea9c4e4baaf7b3ab6 to your computer and use it in GitHub Desktop.
Save hakuch/484ea9c4e4baaf7b3ab6 to your computer and use it in GitHub Desktop.
OCaml monads: candy dispenser example
open Printf
let () =
let open Candy_dispenser in
let dispenser = make ~candies:10 ~coins:3 in
let (candies, coins) = dispenser |> run [Insert_coin; Turn; Insert_coin; Turn; Turn] in
printf "Got %d candies remaining with %d coins.\n" candies coins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment