mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-21 10:49:33 -06:00
Added list patterns. Added som simple prelude functions.
This commit is contained in:
@@ -381,6 +381,8 @@ desugar = return . map f
|
||||
where
|
||||
f :: Tree a -> Tree a
|
||||
f x = case x of
|
||||
PListCons p1 p2 -> pListCons <| p1 <| p2
|
||||
PList xs -> pList (map f [p | PListElem p <- xs])
|
||||
EIf exp0 exp1 exp2 -> ifBool <| exp0 <| exp1 <| exp2
|
||||
EDo bs e -> mkDo (map f bs) (f e)
|
||||
BindNoVar exp0 -> BindVar VWild <| exp0
|
||||
@@ -406,6 +408,16 @@ desugar = return . map f
|
||||
_ -> composOp f x
|
||||
where g <| x = g (f x)
|
||||
|
||||
--
|
||||
-- * List patterns
|
||||
--
|
||||
|
||||
pListCons :: Pattern -> Pattern -> Pattern
|
||||
pListCons p1 p2 = PCons (Ident "Cons") [PWild,p1,p2]
|
||||
|
||||
pList :: [Pattern] -> Pattern
|
||||
pList = foldr pListCons (PCons (Ident "Nil") [PWild])
|
||||
|
||||
--
|
||||
-- * Use an overloaded function.
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user