[Fencommits] fenserve: make the body of a forall always be a concat

Benja Fallenstein benja.fallenstein at gmail.com
Fri May 25 19:11:03 EEST 2007


Fri May 25 19:10:56 EEST 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * make the body of a forall always be a concat
diff -rN -u old-fenserve/fendata/Main.hs new-fenserve/fendata/Main.hs
--- old-fenserve/fendata/Main.hs	2007-05-25 19:11:03.000000000 +0300
+++ new-fenserve/fendata/Main.hs	2007-05-25 19:11:03.000000000 +0300
@@ -41,7 +41,7 @@
         ])
         [Call "Blog_post_archive" []]
 
-potion = Concat [Just $ Forall (catType "post") 0 (Just $ AllItems "post") $ Just $
+potion = Concat [Just $ Forall (catType "post") 0 (Just $ AllItems "post") $
     Concat (map Just [Str "<h2>", Field "post" "title" v, Str "</h2>",
                     Str "\n<p>Author: ", Field "post" "author" v,
                     Str "\n<p>", Field "post" "body" v,
@@ -113,7 +113,7 @@
     body = if (isComplete exp)
            then (HTML $ head $ evalStateT (runExp env exp) s)
            else toHTML "(Incomplete expression.)"
-    rendered = let ?state=s; ?link=True; ?name=name in renderExp exp id string
+    rendered = let ?state=s; ?link=not expandable; ?name=name in renderExp exp id string
     env = Map.fromList $ zip [0..length args-1] args
     expanded = expand s exp; expandable = isJust expanded
     expandLink = (para $ link (?root++"potion?exp="++escape' (show e)++"&name="++n) "[edit page]")
diff -rN -u old-fenserve/fendata/PotionTypes.hs new-fenserve/fendata/PotionTypes.hs
--- old-fenserve/fendata/PotionTypes.hs	2007-05-25 19:11:03.000000000 +0300
+++ new-fenserve/fendata/PotionTypes.hs	2007-05-25 19:11:03.000000000 +0300
@@ -25,7 +25,7 @@
          | Field Category Field (Maybe Exp)
          | AllItems Category
          | Var Int
-         | Forall Type Int (Maybe Exp) (Maybe Exp)
+         | Forall Type Int (Maybe Exp) Exp -- body should always be a Concat
          | Concat [Maybe Exp]
          | Str String
     deriving (Read, Show, Typeable, Data, Eq, Ord)
diff -rN -u old-fenserve/fendata/Potions.hs new-fenserve/fendata/Potions.hs
--- old-fenserve/fendata/Potions.hs	2007-05-25 19:11:03.000000000 +0300
+++ new-fenserve/fendata/Potions.hs	2007-05-25 19:11:03.000000000 +0300
@@ -28,10 +28,9 @@
 
 getPotions :: MyState -> [Exp]
 getPotions s = map f (Map.toList $ statePotions s)
-            ++ [Concat []]
             ++ concatFor (Map.toList $ stateSchema s) (\(cat,fs) ->
                    AllItems cat
-                 : Forall (catType cat) 0 Nothing Nothing
+                 : Forall (catType cat) 0 Nothing (Concat [])
                  : map (\f -> Field cat f Nothing) fs) where
     f (n, Fun ts _ _) = Call n (replicate (length ts) Nothing)
 
@@ -71,7 +70,7 @@
 renderExp exp@(Var i) cx ty = editLink cx exp ty (renderVar i)
 renderExp e0@(Forall t i exp body) cx _ = editLink cx e0 string "For each of " +++ renderMaybeExp' exp (\e -> cx $ Forall t i (Just e) body) t
                             +++ editLink cx e0 string (" (call it '" +++ renderVar i +++ "'):\n")
-                            +++ tag' "blockquote" (renderMaybeExp body (\e -> cx $ Forall t i exp (Just e)) string)
+                            +++ tag' "blockquote" (renderExp body (\e -> cx $ Forall t i exp e) string)
 renderExp (Str s) cx _ = tag "small" [] $ quoteP s
 renderExp exp@(Concat exps) cx _ = para $ catMap (\(xs,x,xs') -> renderMaybeExp' x (\e -> cx (Concat (xs ++ [Just e] ++ xs'))) string) (slices exps) +++ if ?link then para $ editLink cx exp string "[edit]" else toHTML ""
 
@@ -88,7 +87,7 @@
 isComplete (Call _ args)  = all (maybe False isComplete) args
 isComplete (Field _ _ exp) = maybe False isComplete exp
 isComplete (AllItems _) = True
-isComplete (Forall _ _ exp body) = all (maybe False isComplete) [exp, body]
+isComplete (Forall _ _ exp body) = maybe False isComplete exp && isComplete body
 isComplete (Var _)        = True
 isComplete (Concat exps)    = all (maybe False isComplete) exps
 isComplete (Str _)        = True
@@ -105,7 +104,7 @@
 runExp env (AllItems cat) = do
     state <- get
     msum [return $ show n | (n, Item _ cs) <- Map.toList (stateItems state), cat `Set.member` cs]
-runExp env (Forall _ v (Just exp) (Just body)) = do 
+runExp env (Forall _ v (Just exp) body) = do 
     state <- get; let xs = evalStateT (runExp env exp) state
     rs <- forM xs $ \x -> runExp (Map.insert v x env) body
     return $ concat rs




More information about the Fencommits mailing list