Skip to content

Instantly share code, notes, and snippets.

@thealmarty
Last active December 13, 2018 17:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thealmarty/2bfa5923f1d6c45c3c19025184d7cc61 to your computer and use it in GitHub Desktop.
unfold function in OCaml, with a use example.
let rec unfold p g b =
if p b then [] else
(match g b with (a, bprime) ->
a :: unfold p g bprime)
;;
(*Implement the example: *)
let example = unfold (fun x -> (x > 9)) (fun x -> (x, (x + 1)));;
@thealmarty
Copy link
Author

See my blog post for more explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment