# HG changeset patch # User Adam Chlipala # Date 1253213858 14400 # Node ID 301530da206211979ceb1fc748b4206026e710e8 # Parent 07569af4006935f58099e5959a68239d979736a6 Bad sort functions tested diff -r 07569af40069 -r 301530da2062 demo/more/dlist.ur --- a/demo/more/dlist.ur Thu Sep 17 14:42:02 2009 -0400 +++ b/demo/more/dlist.ur Thu Sep 17 14:57:38 2009 -0400 @@ -79,11 +79,57 @@ fun renderFlat [ctx] [ctx ~ body] [t] (f : t -> position -> xml (ctx ++ body) [] []) filter ls = List.mapX (fn p => f p.1 p.2) ls -fun render [ctx] [ctx ~ body] [t] f r dl = - acc + | x1 :: [] => (x1 :: acc.1, acc.2) + | x1 :: x2 :: ls => split' (x1 :: acc.1, x2 :: acc.2) ls + in + split' ([], []) + end + +fun merge [t] (cmp : t -> t -> signal bool) = + let + fun merge' acc (ls1 : list t) (ls2 : list t) = + case (ls1, ls2) of + ([], _) => return (List.revAppend acc ls2) + | (_, []) => return (List.revAppend acc ls1) + | (x1 :: ls1', x2 :: ls2') => + b <- cmp x1 x2; + if b then + merge' (x1 :: acc) ls1' ls2 + else + merge' (x2 :: acc) ls1 ls2' + in + merge' [] + end + +fun sort [t] (cmp : t -> t -> signal bool) = + let + fun sort' (ls : list t) = + case ls of + [] => return ls + | _ :: [] => return ls + | _ => + let + val (ls1, ls2) = split ls + in + ls1' <- sort' ls1; + ls2' <- sort' ls2; + merge cmp ls1' ls2' + end + in + sort' + end + +fun render [ctx] [ctx ~ body] [t] f (r : {Filter : t -> signal bool, + Sort : signal (option (t -> t -> signal bool))}) dl = + return (renderDyn f r.Filter dl) - | Some sort => + | Some cmp => dl' <- signal dl; elems <- (case dl' of Empty => return [] @@ -104,6 +150,7 @@ in listOut None hd [] end); + elems <- sort (fn v1 v2 => cmp v1.1 v2.1) elems; return (renderFlat f r.Filter elems)}/> diff -r 07569af40069 -r 301530da2062 demo/more/grid.ur --- a/demo/more/grid.ur Thu Sep 17 14:42:02 2009 -0400 +++ b/demo/more/grid.ur Thu Sep 17 14:57:38 2009 -0400 @@ -213,7 +213,7 @@ return (previous && this)) (fn _ => return True) [_] M.folder M.cols grid.Cols grid.Filters row, - Sort = return None} + Sort = return (Some (fn _ _ => return False))} grid.Rows} Monad.mapR2 [aggregateMeta M.row] [id] [id]