# HG changeset patch # User Adam Chlipala # Date 1253212020 14400 # Node ID 103ac1792c418708e64f5c6882baa3f0dd5e1952 # Parent 5be3d19b59f3a4962e4bd3f7719bd0823fa0c5f6 Make filter argument to render, not create diff -r 5be3d19b59f3 -r 103ac1792c41 demo/more/dlist.ur --- a/demo/more/dlist.ur Thu Sep 17 13:44:08 2009 -0400 +++ b/demo/more/dlist.ur Thu Sep 17 14:27:00 2009 -0400 @@ -6,19 +6,18 @@ 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 @@ 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 @@ 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 @@ None => headPos dl | Some prev => tailPos prev tl tlTop in - return [] | Nonempty {Head = hd, ...} => elements' hd @@ -107,7 +103,7 @@ 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 diff -r 5be3d19b59f3 -r 103ac1792c41 demo/more/dlist.urs --- a/demo/more/dlist.urs Thu Sep 17 13:44:08 2009 -0400 +++ b/demo/more/dlist.urs Thu Sep 17 14:27:00 2009 -0400 @@ -1,7 +1,7 @@ con dlist :: Type -> Type type position -val create : t ::: Type -> {Filter : t -> signal bool} -> transaction (dlist t) +val create : t ::: Type -> transaction (dlist t) val clear : t ::: Type -> dlist t -> transaction unit val append : t ::: Type -> dlist t -> t -> transaction position val delete : position -> transaction unit @@ -10,5 +10,6 @@ val render : ctx ::: {Unit} -> [ctx ~ body] => t ::: Type -> (t -> position -> xml (ctx ++ body) [] []) + -> {Filter : t -> signal bool} -> dlist t -> xml (ctx ++ body) [] [] diff -r 5be3d19b59f3 -r 103ac1792c41 demo/more/grid.ur --- a/demo/more/grid.ur Thu Sep 17 13:44:08 2009 -0400 +++ b/demo/more/grid.ur Thu Sep 17 14:27:00 2009 -0400 @@ -80,19 +80,13 @@ (meta.Handlers state).CreateFilter) [_] M.folder M.cols cols; - rows <- Dlist.create {Filter = fn all => - row <- signal all.Row; - foldR3 [colMeta M.row] [fst3] [thd3] [fn _ => M.row -> signal bool] - (fn [nm :: Name] [p :: (Type * Type * Type)] - [rest :: {(Type * Type * Type)}] [[nm] ~ rest] - meta state filter combinedFilter row => - previous <- combinedFilter row; - this <- (meta.Handlers state).Filter filter row; - return (previous && this)) - (fn _ => return True) - [_] M.folder M.cols cols filters row}; + rows <- Dlist.create; sel <- source False; - return {Cols = cols, Rows = rows, Selection = sel, Filters = filters} + + return {Cols = cols, + Rows = rows, + Selection = sel, + Filters = filters} fun sync {Cols = cols, Rows = rows, ...} = Dlist.clear rows; @@ -207,7 +201,19 @@ ) [_] M.folder grid.Cols M.cols cols)}/> - end) grid.Rows} + end) + {Filter = fn all => + row <- signal all.Row; + foldR3 [colMeta M.row] [fst3] [thd3] [fn _ => M.row -> signal bool] + (fn [nm :: Name] [p :: (Type * Type * Type)] + [rest :: {(Type * Type * Type)}] [[nm] ~ rest] + meta state filter combinedFilter row => + previous <- combinedFilter row; + this <- (meta.Handlers state).Filter filter row; + return (previous && this)) + (fn _ => return True) + [_] M.folder M.cols grid.Cols grid.Filters row} + grid.Rows} Monad.mapR2 [aggregateMeta M.row] [id] [id] (fn [nm :: Name] [t :: Type] meta acc =>