From e2170d73e8d43842996910a6b512df89e20be389 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 17 Sep 2009 14:27:00 -0400 Subject: Make filter argument to render, not create --- demo/more/dlist.ur | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'demo/more/dlist.ur') diff --git a/demo/more/dlist.ur b/demo/more/dlist.ur index d4a255ee..a99244ec 100644 --- a/demo/more/dlist.ur +++ b/demo/more/dlist.ur @@ -6,19 +6,18 @@ datatype dlist' t = Empty | Nonempty of { Head : dlist'' t, Tail : source (source (dlist'' t)) } -con dlist t = {Filter: t -> signal bool, - Elements : source (dlist' t)} +con dlist t = source (dlist' t) type position = transaction unit fun headPos [t] (dl : dlist t) = - dl' <- get dl.Elements; + dl' <- get dl; case dl' of Nonempty { Head = Cons (_, tl), Tail = tl' } => cur <- get tl; - set dl.Elements (case cur of - Nil => Empty - | _ => Nonempty {Head = cur, Tail = tl'}) + set dl (case cur of + Nil => Empty + | _ => Nonempty {Head = cur, Tail = tl'}) | _ => return () fun tailPos [t] (cur : source (dlist'' t)) new tail = @@ -29,20 +28,17 @@ fun tailPos [t] (cur : source (dlist'' t)) new tail = Nil => set tail cur | _ => return () -fun create [t] r = - s <- source Empty; - return {Filter = r.Filter, - Elements = s} +val create [t] = source Empty -fun clear [t] (s : dlist t) = set s.Elements Empty +fun clear [t] (s : dlist t) = set s Empty fun append [t] dl v = - dl' <- get dl.Elements; + dl' <- get dl; case dl' of Empty => tl <- source Nil; tl' <- source tl; - set dl.Elements (Nonempty {Head = Cons (v, tl), Tail = tl'}); + set dl (Nonempty {Head = Cons (v, tl), Tail = tl'}); return (headPos dl) | Nonempty {Tail = tl, ...} => @@ -52,8 +48,8 @@ fun append [t] dl v = set tl new; return (tailPos cur new tl) -fun render [ctx] [ctx ~ body] [t] f dl = - + | Nonempty {Head = hd, Tail = tlTop} => @@ -67,7 +63,7 @@ fun render [ctx] [ctx ~ body] [t] f dl = None => headPos dl | Some prev => tailPos prev tl tlTop in - return [] | Nonempty {Head = hd, ...} => elements' hd @@ -107,7 +103,7 @@ fun foldl [t] [acc] (f : t -> acc -> signal acc) = foldl'' i' dl' fun foldl' (i : acc) (dl : dlist t) : signal acc = - dl <- signal dl.Elements; + dl <- signal dl; case dl of Empty => return i | Nonempty {Head = dl, ...} => foldl'' i dl -- cgit v1.2.3