summaryrefslogtreecommitdiff
path: root/prototypes
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2015-12-10 12:24:27 +0100
committerPéter Diviánszky <divipp@gmail.com>2015-12-10 12:24:27 +0100
commit6cc20b133ecc5b8e24623cf94cd874510848851b (patch)
treef5801917f5eddb4812487709abfb1c3c053938b1 /prototypes
parentf8d926d87d9d5b41e2d3175adff43e3d8897d2a1 (diff)
fix two bugs in list comprehension compilation
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/Infer.hs19
1 files changed, 11 insertions, 8 deletions
diff --git a/prototypes/Infer.hs b/prototypes/Infer.hs
index 636665af..85fc9537 100644
--- a/prototypes/Infer.hs
+++ b/prototypes/Infer.hs
@@ -1552,16 +1552,16 @@ generator, letdecl, boolExpression :: Namespace -> DBNames -> P (DBNames, SExp -
1552generator ns dbs = do 1552generator ns dbs = do
1553 (dbs', pat) <- try $ pattern' ns dbs <* operator "<-" 1553 (dbs', pat) <- try $ pattern' ns dbs <* operator "<-"
1554 exp <- parseTerm ns PrecLam dbs 1554 exp <- parseTerm ns PrecLam dbs
1555 return $ (,) (join traceShow dbs') $ \e -> application 1555 return $ (,) ({-join traceShow-} dbs') $ \e -> application
1556 [ SGlobal "concatMap" 1556 [ SGlobal "concatMap"
1557 , SLam Visible (Wildcard SType) $ compileGuardTree' $ Alts 1557 , SLam Visible (Wildcard SType) $ compileGuardTree' $ Alts
1558 [ compilePatts [(pat, 0)] Nothing $ preExp $ \dcls -> upS $ removePreExpsE dcls e 1558 [ compilePatts [(pat, 0)] Nothing $ preExp $ \dcls -> {-upS $ -} removePreExpsE dcls e
1559 , GuardLeaf $ SGlobal "Nil" 1559 , GuardLeaf $ SGlobal "Nil"
1560 ] 1560 ]
1561 , exp 1561 , exp
1562 ] 1562 ]
1563 1563
1564letdecl ns dbs = keyword "let" *> ((\((dbs', p), e) -> (join traceShow dbs' ++ dbs, \exp -> mkLets' [ValueDef (dbs', p) e] exp)) <$> valueDef ns dbs) 1564letdecl ns dbs = keyword "let" *> ((\((dbs', p), e) -> ({-join traceShow dbs' ++ -} dbs, \exp -> preExp $ \dcls -> {-traceShow (removePreExpsE dcls exp) $ -} removePreExpsE dcls $ mkLets' [ValueDef (dbs', p) e] exp)) <$> valueDef ns dbs)
1565 1565
1566boolExpression ns dbs = do 1566boolExpression ns dbs = do
1567 pred <- parseTerm ns PrecLam dbs 1567 pred <- parseTerm ns PrecLam dbs
@@ -1570,9 +1570,9 @@ boolExpression ns dbs = do
1570application = foldl1 SAppV 1570application = foldl1 SAppV
1571 1571
1572listCompr :: Namespace -> DBNames -> P SExp 1572listCompr :: Namespace -> DBNames -> P SExp
1573listCompr ns dbs = (\e (dbs', fs) -> foldr ($) (preExp $ \dcls -> deBruinify (take (length dbs' - length dbs) dbs') $ removePreExpsE dcls e) fs) <$> 1573listCompr ns dbs = (\e (dbs', fs) -> foldr ($) (preExp $ \dcls -> deBruinify (take (length dbs' - length dbs) dbs') $ removePreExpsE dcls e) fs)
1574 try' "List comprehension" ((SGlobal "singleton" `SAppV`) <$ operator "[" <*> parseTerm ns PrecLam dbs <* operator "|") <*> 1574 <$> try' "List comprehension" ((SGlobal "singleton" `SAppV`) <$ operator "[" <*> parseTerm ns PrecLam dbs <* operator "|")
1575 commaSep' (liftA2 (<|>) (generator ns) $ liftA2 (<|>) (letdecl ns) (boolExpression ns)) dbs <* operator "]" 1575 <*> commaSep' (liftA2 (<|>) (generator ns) $ liftA2 (<|>) (letdecl ns) (boolExpression ns)) dbs <* operator "]"
1576 1576
1577deBruinify :: DBNames -> SExp -> SExp 1577deBruinify :: DBNames -> SExp -> SExp
1578deBruinify [] e = e 1578deBruinify [] e = e
@@ -1659,10 +1659,13 @@ getTTuple _ = Nothing
1659 1659
1660mkLets' ss e = preExp $ \ge -> mkLets (removePreExps ge ss) (removePreExpsE ge e) 1660mkLets' ss e = preExp $ \ge -> mkLets (removePreExps ge ss) (removePreExpsE ge e)
1661 1661
1662mkLets :: [Stmt] -> SExp -> SExp 1662mkLets :: [Stmt]{-where block-} -> SExp{-main expression-} -> SExp{-big let with lambdas; replaces global names with de bruijn indices-}
1663mkLets [] e = e 1663mkLets [] e = e
1664mkLets (Let n _ Nothing (downS 0 -> Just x): ds) e = SLet x (substSG n (SVar 0) $ upS $ mkLets ds e) 1664mkLets (Let n _ Nothing (downS 0 -> Just x): ds) e = SLet x (substSG n (SVar 0) $ upS $ mkLets ds e)
1665mkLets (ValueDef (ns, p) x: ds) e = patLam p (foldl (\e n -> substSG n (SVar 0) $ upS e) (mkLets ds e) ns) `SAppV` x 1665mkLets (ValueDef (ns, p) x: ds) e =
1666 (\res -> {-preExp $ \dcls -> trace_ ("mkLets valuedef\n" ++ show (ns, p, x, ds, e) ++ "\n" ++ show (removePreExpsE dcls res)) -} res)
1667 $
1668 patLam p (foldl (\e n -> substSG n (SVar 0) $ upS e) (mkLets ds e) ns) `SAppV` x
1666mkLets (x: ds) e = error $ "mkLets: " ++ show x 1669mkLets (x: ds) e = error $ "mkLets: " ++ show x
1667 -- (p = e; f) --> (\p -> f) e 1670 -- (p = e; f) --> (\p -> f) e
1668 1671