Skip to content

Instantly share code, notes, and snippets.

@thealmarty
Created January 1, 2019 23:28
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 thealmarty/be975b8a4386ce4d823acd4c7e957cd5 to your computer and use it in GitHub Desktop.
Save thealmarty/be975b8a4386ce4d823acd4c7e957cd5 to your computer and use it in GitHub Desktop.
zip3 function in OCaml.
(* Define the unfold function that takes 3 inputs.*)
let rec unfold p g b1 b2 b3 =
if p b1 b2 b3 then [] else
(match g b1 b2 b3 with (a, (b1prime, b2prime, b3prime)) ->
a :: unfold p g b1prime b2prime b3prime)
;;
(* Define the zip3 function.*)
let zip3 = unfold
(* Define p.*)
(fun x y z -> ((List.length x = 0) || (List.length y = 0) || (List.length z =
0) ))
(* Define g.*)
(fun x y z -> ( (List.hd x, List.hd y, List.hd z), (List.tl x, List.tl y, List
.tl z)))
;;
@thealmarty
Copy link
Author

See my blog post.

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