Created
January 1, 2019 23:28
-
-
Save thealmarty/be975b8a4386ce4d823acd4c7e957cd5 to your computer and use it in GitHub Desktop.
zip3 function in OCaml.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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))) | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my blog post.