Created
November 21, 2017 14:54
-
-
Save gofer/a1d5b03eeca32d7e5f672fdf85aafdeb to your computer and use it in GitHub Desktop.
Sub List
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
(* subList : 'a list -> 'a list list *) | |
fun subList v = | |
List.foldl | |
List.@ | |
[ nil ] | |
( | |
List.map | |
( | |
fn x => ( | |
fn v => | |
List.map | |
(fn x => List.take (v, x)) | |
(List.tabulate ((List.length v), (fn x => x + 1))) | |
) | |
(List.drop (v, x)) | |
) | |
(List.rev(List.tabulate ((List.length v) + 1, (fn x => x)))) | |
); | |
(* Example*) | |
val v = [1, 2, 3, 4, 5, 6]; | |
val () = print ((listToString (fn v => listToString Int.toString v) (subList v)) ^ "\n"); | |
val v = ["A", "B", "C", "D", "E"]; | |
val () = print ((listToString (fn v => listToString (fn s => s) v) (subList v)) ^ "\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment