Skip to content

Instantly share code, notes, and snippets.

@linstantnoodles
Last active December 10, 2015 04:28
Show Gist options
  • Save linstantnoodles/4381630 to your computer and use it in GitHub Desktop.
Save linstantnoodles/4381630 to your computer and use it in GitHub Desktop.
let rec sublists a = match a with
[] -> [[]]
|first::rest -> let b = sublists rest in
let c = List.map (fun g -> first::g) b in
c @ b;;
(*
val sublists : 'a list -> 'a list list = <fun>
# let a = [1;2;3];;
val a : int list = [1; 2; 3]
# sublists a;;
- : int list list = [[1; 2; 3]; [1; 2]; [1; 3]; [1]; [2; 3]; [2]; [3]; []]
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment