summaryrefslogtreecommitdiff
path: root/demo/more/dlist.ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-09-17 14:27:00 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-09-17 14:27:00 -0400
commite2170d73e8d43842996910a6b512df89e20be389 (patch)
treeaf4f0a5cad40b9adf26dafdbb4d1321fa4976e57 /demo/more/dlist.ur
parent4c34d3d6afd313df90273eb4aafcd0a08c4def22 (diff)
Make filter argument to render, not create
Diffstat (limited to 'demo/more/dlist.ur')
-rw-r--r--demo/more/dlist.ur32
1 files changed, 14 insertions, 18 deletions
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 = <xml>
- <dyn signal={dl' <- signal dl.Elements;
+fun render [ctx] [ctx ~ body] [t] f {Filter = filter, ...} dl = <xml>
+ <dyn signal={dl' <- signal dl;
return (case dl' of
Empty => <xml/>
| Nonempty {Head = hd, Tail = tlTop} =>
@@ -67,7 +63,7 @@ fun render [ctx] [ctx ~ body] [t] f dl = <xml>
None => headPos dl
| Some prev => tailPos prev tl tlTop
in
- <xml><dyn signal={b <- dl.Filter v;
+ <xml><dyn signal={b <- filter v;
return (if b then
f v pos
else
@@ -91,7 +87,7 @@ fun elements' [t] (dl'' : dlist'' t) =
return (x :: tl)
fun elements [t] (dl : dlist t) =
- dl' <- signal dl.Elements;
+ dl' <- signal dl;
case dl' of
Empty => 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