Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* Return a function that maps list items using a given function lambda *)
- fun map(lambda) = fn ([]) => []
- | (x::[]) => [lambda(x)]
- | (xs) => lambda(hd(xs)) :: map(lambda)(tl(xs));
- (* Return a list of all k element sublists of xs *)
- fun choose(0, xs) = [[]]
- | choose(1, xs) = map(fn x => [x])(xs)
- | choose(k, xs) = if k > length(xs) then []
- else if k = length(xs) then [xs]
- (* The previous case of tl(xs) as well as all the new sublists with
- the head *)
- else choose(k, tl(xs)) @ map(fn y => hd(xs) :: y)(choose(k-1, tl(xs)));
Add Comment
Please, Sign In to add comment