Skip to content

Instantly share code, notes, and snippets.

@gallais
Last active March 7, 2017 20:37
Show Gist options
  • Save gallais/71a30a74e2d6090a75873a114f4ea14f to your computer and use it in GitHub Desktop.
Save gallais/71a30a74e2d6090a75873a114f4ea14f to your computer and use it in GitHub Desktop.
open List
let bind (xs : 'a list) (f : 'a -> 'b list) : 'b list =
concat (map f xs)
let rec parts : 'a list -> 'a list list list = function
| [] -> [[]]
| [c] -> [[[c]]]
| c :: cs ->
bind (parts cs) (fun (p :: ps) ->
[(c :: p) :: ps; [c]::p::ps])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment