Stdlib overhaul #624

Merged
zxq9 merged 12 commits from stdlib-overhaul into master 2019-08-28 15:38:40 +09:00
2 changed files with 7 additions and 9 deletions
Showing only changes of commit e7d3a5b9f2 - Show all commits

View File

@ -102,10 +102,8 @@ namespace List =
[] => reverse(acc) [] => reverse(acc)
h::t => map_(f, t, f(h)::acc) h::t => map_(f, t, f(h)::acc)
function flat_map(f : 'a => list('b), l : list('a)) : list('b) = flat_map_(f, l, []) function flat_map(f : 'a => list('b), l : list('a)) : list('b) =
private function flat_map_(f : 'a => list('b), l : list('a), acc : list('b)) : list('b) = switch(l) ListInternal.flat_map(f, l)
[] => reverse(acc)
h::t => flat_map_(f, t, reverse(f(h)) ++ acc)
function filter(p : 'a => bool, l : list('a)) : list('a) = filter_(p, l, []) function filter(p : 'a => bool, l : list('a)) : list('a) = filter_(p, l, [])
private function filter_(p : 'a => bool, l : list('a), acc : list('a)) : list('a) = switch(l) private function filter_(p : 'a => bool, l : list('a), acc : list('a)) : list('a) = switch(l)

View File

@ -1,9 +1,9 @@
namespace ListInternal = namespace ListInternal =
private function reverse_(xs : list('a), ys : list('a)) : list('a) = // -- Flatmap ----------------------------------------------------------------
function flat_map(f : 'a => list('b), xs : list('a)) : list('b) =
switch(xs) switch(xs)
[] => ys [] => []
x :: xs => reverse_(xs, x :: ys) x :: xs => f(x) ++ flat_map(f, xs)
function reverse(xs : list('a)) = reverse_(xs, [])