diff options
Diffstat (limited to 'demo/more/dlist.ur')
-rw-r--r-- | demo/more/dlist.ur | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/demo/more/dlist.ur b/demo/more/dlist.ur index f8aca1e2..850836b0 100644 --- a/demo/more/dlist.ur +++ b/demo/more/dlist.ur @@ -86,3 +86,22 @@ fun elements [t] (dl : dlist t) = case dl' of Empty => return [] | Nonempty {Head = hd, ...} => elements' hd + +fun foldl [t] [acc] (f : t -> acc -> signal acc) = + let + fun foldl'' (i : acc) (dl : dlist'' t) : signal acc = + case dl of + Nil => return i + | Cons (v, dl') => + dl' <- signal dl'; + i' <- f v i; + foldl'' i' dl' + + fun foldl' (i : acc) (dl : dlist t) : signal acc = + dl <- signal dl; + case dl of + Empty => return i + | Nonempty {Head = dl, ...} => foldl'' i dl + in + foldl' + end |