Created
December 6, 2020 15:38
-
-
Save ebresafegaga/0ceddc94a5eade93e49414f58cb4a434 to your computer and use it in GitHub Desktop.
Possibly the world’s first functional pearl (by David Barron and Christopher Strachey) - Cartesian product
This file contains hidden or 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
open ListLabels | |
let product xss = | |
let f xs yss = | |
let g x xs = | |
let h a b = (x :: a) :: b in | |
List.fold_right ~f:h ~init:xs yss | |
in | |
List.fold_right ~f:g ~init:[] xs | |
in | |
List.fold_right ~f:f ~init:[[]] xss | |
(* PS: it looks way nicer in Haskell because of where clauses *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment