diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-03 19:19:29 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-03 19:19:29 +0200 |
commit | d853a6c0f5e027c5e98d96ddd29c21901dd67039 (patch) | |
tree | 5acac233046580343d410f75a815d362c67ecb57 /src | |
parent | f468a49a43193caffe92cdd48a52a699880e14ef (diff) |
better show for let expressions; fix a bug in type class desugaring
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Patterns.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Pretty.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Statements.hs | 9 |
5 files changed, 13 insertions, 8 deletions
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 8efa8e76..ecc2c1b8 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -430,8 +430,8 @@ showLam x (DFreshName u d) = DFreshName u $ showLam (DUp 0 x) d | |||
430 | showLam x (DLam xs y) = DLam (DSep (InfixR 11) x xs) y | 430 | showLam x (DLam xs y) = DLam (DSep (InfixR 11) x xs) y |
431 | showLam x y = DLam x y | 431 | showLam x y = DLam x y |
432 | 432 | ||
433 | shLet i a b = showLam (DLet ":=" (blue $ shVar i) $ DUp i a) (DUp i b) | 433 | shLet i a b = DLet' (DLet "=" (blue $ shVar i) $ DUp i a) (DUp i b) |
434 | shLet_ a b = DFreshName True $ showLam (DLet ":=" (shVar 0) $ DUp 0 a) b | 434 | shLet_ a b = DFreshName True $ DLet' (DLet "=" (shVar 0) $ DUp 0 a) b |
435 | 435 | ||
436 | -------------------------------------------------------------------------------- statement | 436 | -------------------------------------------------------------------------------- statement |
437 | 437 | ||
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index 9350f9fd..10801810 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -419,8 +419,8 @@ parseDef = | |||
419 | constraints <- option [] $ try "constraint" $ getTTuple <$> setR parseTermOp <* reservedOp "=>" | 419 | constraints <- option [] $ try "constraint" $ getTTuple <$> setR parseTermOp <* reservedOp "=>" |
420 | x <- upperCase | 420 | x <- upperCase |
421 | (nps, args) <- telescopePat | 421 | (nps, args) <- telescopePat |
422 | cs <- expNS $ option [] $ reserved "where" *> identation False (deBruijnify nps <$> funAltDef (Just lhsOperator) varId) | 422 | cs <- expNS $ option [] $ reserved "where" *> identation False ({-deBruijnify nps <$> -} funAltDef (Just lhsOperator) varId) |
423 | pure . Instance x ({-todo-}map snd args) (deBruijnify (nps <> [x]) <$> constraints) <$> runCheck (compileStmt' cs) | 423 | pure . Instance x ({-todo-}map snd args) (deBruijnify nps <$> constraints) <$> runCheck (compileStmt' cs) |
424 | <|> do reserved "type" *> do | 424 | <|> do reserved "type" *> do |
425 | typeNS $ do | 425 | typeNS $ do |
426 | reserved "family" *> do | 426 | reserved "family" *> do |
diff --git a/src/LambdaCube/Compiler/Patterns.hs b/src/LambdaCube/Compiler/Patterns.hs index 1483450a..5fcdbc9e 100644 --- a/src/LambdaCube/Compiler/Patterns.hs +++ b/src/LambdaCube/Compiler/Patterns.hs | |||
@@ -305,7 +305,7 @@ compileGuardTree ulend lend si vt = fmap (\e -> foldr (uncurry SLam) e vt) . run | |||
305 | `SAppV` f | 305 | `SAppV` f |
306 | Right n -> do | 306 | Right n -> do |
307 | g1 <- guardTreeToCases (Nothing: path){-TODO-} $ filterGuardTree (up n f) s 0 n $ rUp n 0 ts | 307 | g1 <- guardTreeToCases (Nothing: path){-TODO-} $ filterGuardTree (up n f) s 0 n $ rUp n 0 ts |
308 | g2 <- guardTreeToCases (Nothing: path){-TODO-} (filterGuardTree' f s ts) | 308 | g2 <- guardTreeToCases (Nothing: path){-TODO-} $ filterGuardTree' f s ts |
309 | return $ SGlobal (SIName mempty $ MatchName $ sName s) | 309 | return $ SGlobal (SIName mempty $ MatchName $ sName s) |
310 | `SAppV` SLamV (Wildcard SType) | 310 | `SAppV` SLamV (Wildcard SType) |
311 | `SAppV` iterateN n SLamV g1 | 311 | `SAppV` iterateN n SLamV g1 |
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs index 034df19d..ca39325f 100644 --- a/src/LambdaCube/Compiler/Pretty.hs +++ b/src/LambdaCube/Compiler/Pretty.hs | |||
@@ -210,7 +210,6 @@ renderDoc | |||
210 | DPreOp _ op y -> renderA op <++> render' y | 210 | DPreOp _ op y -> renderA op <++> render' y |
211 | DSep (InfixR 11) a b -> gr $ render' a <+++> render' b | 211 | DSep (InfixR 11) a b -> gr $ render' a <+++> render' b |
212 | x@DApp{} -> case getApps x of | 212 | x@DApp{} -> case getApps x of |
213 | -- (DText "List", [x]) -> gr $ rtext "[" <+++> render' x <++> rtext "]" | ||
214 | (n, reverse -> xs) -> ((\xs -> (fst $ head xs, snd $ last xs)) *** P.nest 2 . P.sep) (unzip $ render' n: (render' <$> xs)) | 213 | (n, reverse -> xs) -> ((\xs -> (fst $ head xs, snd $ last xs)) *** P.nest 2 . P.sep) (unzip $ render' n: (render' <$> xs)) |
215 | DInfix _ x op y -> gr $ render' x <+++> renderA op <++> render' y | 214 | DInfix _ x op y -> gr $ render' x <+++> renderA op <++> render' y |
216 | 215 | ||
@@ -329,6 +328,7 @@ pattern DForall s vs e = DArr_ s (DPreOp 10 (SimpleAtom "forall") vs) e | |||
329 | pattern DContext vs e = DArr_ "=>" vs e | 328 | pattern DContext vs e = DArr_ "=>" vs e |
330 | pattern DParContext vs e = DContext (DParen vs) e | 329 | pattern DParContext vs e = DContext (DParen vs) e |
331 | pattern DLam vs e = DPreOp (-10) (ComplexAtom "\\" 11 vs (SimpleAtom "->")) e | 330 | pattern DLam vs e = DPreOp (-10) (ComplexAtom "\\" 11 vs (SimpleAtom "->")) e |
331 | pattern DLet' vs e = DPreOp (-10) (ComplexAtom "let" (-20) vs (SimpleAtom "in")) e | ||
332 | 332 | ||
333 | -------------------------------------------------------------------------------- | 333 | -------------------------------------------------------------------------------- |
334 | 334 | ||
diff --git a/src/LambdaCube/Compiler/Statements.hs b/src/LambdaCube/Compiler/Statements.hs index 2f1b5859..7d6b3970 100644 --- a/src/LambdaCube/Compiler/Statements.hs +++ b/src/LambdaCube/Compiler/Statements.hs | |||
@@ -59,6 +59,9 @@ addFix n x | |||
59 | | usedS n x = SBuiltin "primFix" `SAppV` SLamV (deBruijnify [n] x) | 59 | | usedS n x = SBuiltin "primFix" `SAppV` SLamV (deBruijnify [n] x) |
60 | | otherwise = x | 60 | | otherwise = x |
61 | 61 | ||
62 | addFix' (Let n nt nd) = Let n nt $ addFix n nd | ||
63 | addFix' x = x | ||
64 | |||
62 | type DefinedSet = Set.Set SName | 65 | type DefinedSet = Set.Set SName |
63 | 66 | ||
64 | addForalls :: DefinedSet -> SExp -> SExp | 67 | addForalls :: DefinedSet -> SExp -> SExp |
@@ -99,7 +102,7 @@ compileStmt compilegt ds = \case | |||
99 | -- , let ic = patVars i | 102 | -- , let ic = patVars i |
100 | ] | 103 | ] |
101 | ] | 104 | ] |
102 | return $ cd ++ concat cds | 105 | return $ map addFix' cd ++ concat cds |
103 | [TypeAnn n t] -> return [Primitive n t | n `notElem` [n' | FunAlt n' _ _ <- ds]] | 106 | [TypeAnn n t] -> return [Primitive n t | n `notElem` [n' | FunAlt n' _ _ <- ds]] |
104 | tf@[TypeFamily n t] -> case [d | d@(FunAlt n' _ _) <- ds, n' == n] of | 107 | tf@[TypeFamily n t] -> case [d | d@(FunAlt n' _ _) <- ds, n' == n] of |
105 | [] -> return [Primitive n t] | 108 | [] -> return [Primitive n t] |
@@ -134,9 +137,11 @@ desugarValueDef p e = sequence | |||
134 | getLet (Let x Nothing (SRHS dx)) = Just (x, dx) | 137 | getLet (Let x Nothing (SRHS dx)) = Just (x, dx) |
135 | getLet _ = Nothing | 138 | getLet _ = Nothing |
136 | 139 | ||
140 | fst' (x, _) = x -- TODO | ||
141 | |||
137 | desugarMutual :: {-MonadWriter [ParseCheck] m => -} [Stmt] -> [Stmt] | 142 | desugarMutual :: {-MonadWriter [ParseCheck] m => -} [Stmt] -> [Stmt] |
138 | desugarMutual [x] = [x] | 143 | desugarMutual [x] = [x] |
139 | desugarMutual (traverse getLet -> Just (unzip -> (ns, ds))) = fst{-TODO-} $ runWriter $ do | 144 | desugarMutual (traverse getLet -> Just (unzip -> (ns, ds))) = fst' $ runWriter $ do |
140 | ss <- compileStmt' =<< desugarValueDef (foldr cHCons cHNil $ PVarSimp <$> ns) (SGlobal xy) | 145 | ss <- compileStmt' =<< desugarValueDef (foldr cHCons cHNil $ PVarSimp <$> ns) (SGlobal xy) |
141 | return $ | 146 | return $ |
142 | Let xy Nothing (addFix xy $ SRHS $ mkLets' SLet ss $ foldr HCons HNil ds) : ss | 147 | Let xy Nothing (addFix xy $ SRHS $ mkLets' SLet ss $ foldr HCons HNil ds) : ss |