diff options
author | Péter Diviánszky <divipp@gmail.com> | 2015-12-10 12:24:27 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2015-12-10 12:24:27 +0100 |
commit | 6cc20b133ecc5b8e24623cf94cd874510848851b (patch) | |
tree | f5801917f5eddb4812487709abfb1c3c053938b1 /prototypes | |
parent | f8d926d87d9d5b41e2d3175adff43e3d8897d2a1 (diff) |
fix two bugs in list comprehension compilation
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/Infer.hs | 19 |
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 - | |||
1552 | generator ns dbs = do | 1552 | generator 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 | ||
1564 | letdecl ns dbs = keyword "let" *> ((\((dbs', p), e) -> (join traceShow dbs' ++ dbs, \exp -> mkLets' [ValueDef (dbs', p) e] exp)) <$> valueDef ns dbs) | 1564 | letdecl 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 | ||
1566 | boolExpression ns dbs = do | 1566 | boolExpression ns dbs = do |
1567 | pred <- parseTerm ns PrecLam dbs | 1567 | pred <- parseTerm ns PrecLam dbs |
@@ -1570,9 +1570,9 @@ boolExpression ns dbs = do | |||
1570 | application = foldl1 SAppV | 1570 | application = foldl1 SAppV |
1571 | 1571 | ||
1572 | listCompr :: Namespace -> DBNames -> P SExp | 1572 | listCompr :: Namespace -> DBNames -> P SExp |
1573 | listCompr ns dbs = (\e (dbs', fs) -> foldr ($) (preExp $ \dcls -> deBruinify (take (length dbs' - length dbs) dbs') $ removePreExpsE dcls e) fs) <$> | 1573 | listCompr 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 | ||
1577 | deBruinify :: DBNames -> SExp -> SExp | 1577 | deBruinify :: DBNames -> SExp -> SExp |
1578 | deBruinify [] e = e | 1578 | deBruinify [] e = e |
@@ -1659,10 +1659,13 @@ getTTuple _ = Nothing | |||
1659 | 1659 | ||
1660 | mkLets' ss e = preExp $ \ge -> mkLets (removePreExps ge ss) (removePreExpsE ge e) | 1660 | mkLets' ss e = preExp $ \ge -> mkLets (removePreExps ge ss) (removePreExpsE ge e) |
1661 | 1661 | ||
1662 | mkLets :: [Stmt] -> SExp -> SExp | 1662 | mkLets :: [Stmt]{-where block-} -> SExp{-main expression-} -> SExp{-big let with lambdas; replaces global names with de bruijn indices-} |
1663 | mkLets [] e = e | 1663 | mkLets [] e = e |
1664 | mkLets (Let n _ Nothing (downS 0 -> Just x): ds) e = SLet x (substSG n (SVar 0) $ upS $ mkLets ds e) | 1664 | mkLets (Let n _ Nothing (downS 0 -> Just x): ds) e = SLet x (substSG n (SVar 0) $ upS $ mkLets ds e) |
1665 | mkLets (ValueDef (ns, p) x: ds) e = patLam p (foldl (\e n -> substSG n (SVar 0) $ upS e) (mkLets ds e) ns) `SAppV` x | 1665 | mkLets (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 | ||
1666 | mkLets (x: ds) e = error $ "mkLets: " ++ show x | 1669 | mkLets (x: ds) e = error $ "mkLets: " ++ show x |
1667 | -- (p = e; f) --> (\p -> f) e | 1670 | -- (p = e; f) --> (\p -> f) e |
1668 | 1671 | ||