diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-02 13:53:20 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-02 13:53:20 +0200 |
commit | 8d0414f3751ecba2d7dcffecadbfa6cd50d2daaf (patch) | |
tree | b2d9c199e1ba9f141fca7c66fa4c15edd14399e7 /src | |
parent | 128cf82881352cc1e9061db97fe3762315cfd0c9 (diff) |
complete pShow on patterns; bugfix; more uncovered warning tests
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 16 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Patterns.hs | 46 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Pretty.hs | 9 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Statements.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Utils.hs | 1 |
6 files changed, 40 insertions, 38 deletions
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 7351f4d7..c17717f3 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -450,7 +450,7 @@ instance PShow Stmt where | |||
450 | pShow stmt = DResetFreshNames $ case stmt of | 450 | pShow stmt = DResetFreshNames $ case stmt of |
451 | Primitive n t -> shAnn (pShow n) (pShow t) | 451 | Primitive n t -> shAnn (pShow n) (pShow t) |
452 | Let n ty e -> DLet "=" (pShow n) $ maybe (pShow e) (\ty -> shAnn (pShow e) (pShow ty)) ty | 452 | Let n ty e -> DLet "=" (pShow n) $ maybe (pShow e) (\ty -> shAnn (pShow e) (pShow ty)) ty |
453 | Data n ps ty cs -> nest 4 $ "data" <+> shAnn (foldl dApp (DTypeNamespace True $ pShow n) [shAnn (text "_") (pShow t) | (v, t) <- ps]) (pShow ty) <+> "where" <$$> vcat [shAnn (pShow n) $ pShow t | (n, t) <- cs] | 453 | Data n ps ty cs -> nest 2 $ "data" <+> nest 2 (shAnn (foldl dApp (DTypeNamespace True $ pShow n) [shAnn (text "_") (pShow t) | (v, t) <- ps]) (pShow ty)) </> "where" <> nest 2 (hardline <> vcat [shAnn (pShow n) $ pShow t | (n, t) <- cs]) |
454 | PrecDef n i -> pShow i <+> shortForm (pShow n) --DOp0 (sName n) i | 454 | PrecDef n i -> pShow i <+> shortForm (pShow n) --DOp0 (sName n) i |
455 | 455 | ||
456 | instance DeBruijnify SIName Stmt where | 456 | instance DeBruijnify SIName Stmt where |
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index 633368f8..bf7cd330 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -59,13 +59,13 @@ data LCParseError | |||
59 | 59 | ||
60 | data ParseWarning | 60 | data ParseWarning |
61 | = Unreachable Range | 61 | = Unreachable Range |
62 | | Uncovered SI [PatList] | 62 | | Uncovered SIName [PatList] |
63 | 63 | ||
64 | instance NFData ParseWarning | 64 | instance NFData ParseWarning |
65 | where | 65 | where |
66 | rnf = \case | 66 | rnf = \case |
67 | Unreachable r -> rnf r | 67 | Unreachable r -> rnf r |
68 | Uncovered si r -> rnf si -- TODO --rnf r | 68 | Uncovered si r -> () --rnf si -- TODO --rnf r |
69 | 69 | ||
70 | instance PShow LCParseError where | 70 | instance PShow LCParseError where |
71 | pShow = \case | 71 | pShow = \case |
@@ -78,10 +78,14 @@ instance PShow LCParseError where | |||
78 | instance PShow ParseWarning where | 78 | instance PShow ParseWarning where |
79 | pShow = \case | 79 | pShow = \case |
80 | Unreachable si -> "Source code is not reachable:" <+> pShow si | 80 | Unreachable si -> "Source code is not reachable:" <+> pShow si |
81 | Uncovered si pss -> "Uncovered pattern(s) at" <+> pShow si <$$> "Missing case(s):" <$$> | 81 | Uncovered sn pss -> "Uncovered pattern(s) at" <+> pShow (sourceInfo sn) <$$> |
82 | vcat [" " <> hsep (map pShow ps) <+> | 82 | nest 4 (shortForm $ vcat $ "Missing case(s):" : |
83 | hsep [se <+> pShow p <+> "<-" <+> pShow e | (se, (p, e)) <- zip ("|": repeat ",") gs] | 83 | [ addG (foldl DApp (pShow sn) (pShow <$> ps)) [DOp "<-" (Infix (-1)) (pShow p) (pShow e) | (p, e) <- gs] |
84 | | (ps, gs) <- pss] | 84 | | (ps, gs) <- pss] |
85 | ) | ||
86 | where | ||
87 | addG x [] = x | ||
88 | addG x xs = DOp "|" (Infix (-5)) x $ foldr1 (DOp "," (InfixR (-4))) xs | ||
85 | 89 | ||
86 | trackSI p = do | 90 | trackSI p = do |
87 | x <- p | 91 | x <- p |
@@ -283,7 +287,7 @@ generator = do | |||
283 | checkPattern dbs | 287 | checkPattern dbs |
284 | exp <- setR parseTermLam | 288 | exp <- setR parseTermLam |
285 | return $ \e -> do | 289 | return $ \e -> do |
286 | cf <- runCheck $ compileGuardTree id id (Just $ sourceInfo pat) [(Visible, Wildcard SType)] $ compilePatts [pat] (noGuards $ deBruijnify dbs e) `mappend` noGuards BNil | 290 | cf <- runCheck $ compileGuardTree id id (Just $ SIName (sourceInfo pat) "") [(Visible, Wildcard SType)] $ compilePatts [pat] (noGuards $ deBruijnify dbs e) `mappend` noGuards BNil |
287 | return $ SBuiltin "concatMap" `SAppV` cf `SAppV` exp | 291 | return $ SBuiltin "concatMap" `SAppV` cf `SAppV` exp |
288 | 292 | ||
289 | letdecl = (return .) . mkLets <$ reserved "let" <*> (runCheck . compileStmt' =<< valueDef) | 293 | letdecl = (return .) . mkLets <$ reserved "let" <*> (runCheck . compileStmt' =<< valueDef) |
diff --git a/src/LambdaCube/Compiler/Patterns.hs b/src/LambdaCube/Compiler/Patterns.hs index a2bc3831..fe4ed352 100644 --- a/src/LambdaCube/Compiler/Patterns.hs +++ b/src/LambdaCube/Compiler/Patterns.hs | |||
@@ -15,6 +15,7 @@ import Data.Maybe | |||
15 | import qualified Data.Set as Set | 15 | import qualified Data.Set as Set |
16 | import Control.Monad.Writer | 16 | import Control.Monad.Writer |
17 | import Control.Arrow hiding ((<+>)) | 17 | import Control.Arrow hiding ((<+>)) |
18 | import Debug.Trace | ||
18 | 19 | ||
19 | import LambdaCube.Compiler.Utils | 20 | import LambdaCube.Compiler.Utils |
20 | import LambdaCube.Compiler.DeBruijn | 21 | import LambdaCube.Compiler.DeBruijn |
@@ -26,7 +27,7 @@ import LambdaCube.Compiler.DesugaredSource | |||
26 | data ParseCheck | 27 | data ParseCheck |
27 | = TrackedCode Range | 28 | = TrackedCode Range |
28 | | Reachable Range | 29 | | Reachable Range |
29 | | Uncovered' SI [PatList] | 30 | | Uncovered' SIName [PatList] |
30 | 31 | ||
31 | type PatList = ([ParPat_ ()], [(ParPat_ (), SExp)]) | 32 | type PatList = ([ParPat_ ()], [(ParPat_ (), SExp)]) |
32 | 33 | ||
@@ -38,7 +39,7 @@ type ConsInfo = Either ((SName{-case eliminator name-}, Int{-num of indices-}), | |||
38 | type Pat = Pat_ ConsInfo | 39 | type Pat = Pat_ ConsInfo |
39 | 40 | ||
40 | data Pat_ c | 41 | data Pat_ c |
41 | = PVar SIName -- Int | 42 | = PVar SIName |
42 | | PCon_ SI (SIName, c) [ParPat_ c] | 43 | | PCon_ SI (SIName, c) [ParPat_ c] |
43 | | ViewPat_ SI SExp (ParPat_ c) | 44 | | ViewPat_ SI SExp (ParPat_ c) |
44 | | PatType_ SI (ParPat_ c) SExp | 45 | | PatType_ SI (ParPat_ c) SExp |
@@ -52,9 +53,17 @@ pattern ParPat ps <- ParPat_ _ ps | |||
52 | where ParPat ps = ParPat_ (foldMap sourceInfo ps) ps | 53 | where ParPat ps = ParPat_ (foldMap sourceInfo ps) ps |
53 | 54 | ||
54 | instance PShow (Pat_ a) where | 55 | instance PShow (Pat_ a) where |
55 | pShow = patDoc | 56 | pShow = \case |
57 | PVar sn -> pShow sn | ||
58 | PCon (sn, _) ps -> foldl DApp (pShow sn) (pShow <$> ps) | ||
59 | ViewPat e p -> DOp "->" (Infix (-1)) (pShow e) (pShow p) | ||
60 | PatType p t -> DAnn (pShow p) (pShow t) | ||
61 | |||
56 | instance PShow (ParPat_ a) where | 62 | instance PShow (ParPat_ a) where |
57 | pShow = parPatDoc | 63 | pShow = \case |
64 | ParPat [] -> text "_" | ||
65 | ParPat ps -> foldr1 (DOp "@" (InfixR 11)) $ pShow <$> ps | ||
66 | |||
58 | 67 | ||
59 | 68 | ||
60 | pattern PWildcard si = ParPat_ si [] | 69 | pattern PWildcard si = ParPat_ si [] |
@@ -153,17 +162,6 @@ instance SetSourceInfo (Pat_ c) where | |||
153 | ViewPat_ _ a b -> ViewPat_ si a b | 162 | ViewPat_ _ a b -> ViewPat_ si a b |
154 | PatType_ _ a b -> PatType_ si a b | 163 | PatType_ _ a b -> PatType_ si a b |
155 | 164 | ||
156 | -------------------------------------------------------------------------------- pretty print | ||
157 | |||
158 | patDoc :: Pat_ a -> Doc | ||
159 | patDoc = \case | ||
160 | PCon (n, _) _ -> text $ sName n -- TODO | ||
161 | |||
162 | parPatDoc :: ParPat_ a -> Doc | ||
163 | parPatDoc = \case | ||
164 | ParPat [] -> text "_" | ||
165 | ParPat [p] -> patDoc p | ||
166 | -- TODO | ||
167 | -------------------------------------------------------------------------------- pattern match compilation | 165 | -------------------------------------------------------------------------------- pattern match compilation |
168 | 166 | ||
169 | -- pattern match compilation monad | 167 | -- pattern match compilation monad |
@@ -171,7 +169,7 @@ type PMC = Writer ([CasePath], [Range]) | |||
171 | 169 | ||
172 | type CasePath = [Maybe (SIName, Int, SExp)] | 170 | type CasePath = [Maybe (SIName, Int, SExp)] |
173 | 171 | ||
174 | runPMC :: MonadWriter [ParseCheck] m => Maybe SI -> [(Visibility, SExp)] -> PMC a -> m a | 172 | runPMC :: MonadWriter [ParseCheck] m => Maybe SIName -> [(Visibility, SExp)] -> PMC a -> m a |
175 | runPMC si vt m = do | 173 | runPMC si vt m = do |
176 | tell $ Reachable <$> rs | 174 | tell $ Reachable <$> rs |
177 | case si of | 175 | case si of |
@@ -180,14 +178,16 @@ runPMC si vt m = do | |||
180 | return a | 178 | return a |
181 | where | 179 | where |
182 | (a, (ps, rs)) = runWriter m | 180 | (a, (ps, rs)) = runWriter m |
183 | mkPatt_ ps_ i_ = (ps, mkGuards 0 ps_) | 181 | |
182 | mkPatt_ ps_ is = (ps, mkGuards 0 ps_) | ||
184 | where | 183 | where |
185 | (mconcat -> qs, ps) = unzip $ map (mkPatt 0 ps_) i_ | 184 | (mconcat -> qs, ps) = unzip $ map (mkPatt 0 ps_) is |
186 | 185 | ||
187 | mkGuards k [] = [] | 186 | mkGuards k [] = [] |
188 | mkGuards k ((q, (cn, n, e)): ps) = [(PConSimp (cn, ()) $ replicate n $ PWildcard mempty, e) | q `Set.notMember` qs] ++ mkGuards (k + n) ps | 187 | mkGuards k ((q, (cn, n, e)): ps) = [(PConSimp (cn, ()) $ replicate n $ PWildcard mempty, e) | q `Set.notMember` qs] ++ mkGuards (k + n) ps |
189 | 188 | ||
190 | mkPatt k ((q, (cn, n, SVar _ j)): ps) i | j == (i + k) = (Set.singleton q <>) . mconcat *** PConSimp (cn, ()) $ unzip [mkPatt (k + n) ps l | l <- [n-1, n-2..0]] | 189 | mkPatt k ((q, (cn, n, SVar _ j)): ps) i | j == (i + k) |
190 | = (Set.singleton q <>) . mconcat *** PConSimp (cn, ()) $ unzip [mkPatt 0 ps l | l <- [n-1, n-2..0]] | ||
191 | mkPatt k ((q, (cn, n, _)): ps) i = mkPatt (k + n) ps i | 191 | mkPatt k ((q, (cn, n, _)): ps) i = mkPatt (k + n) ps i |
192 | mkPatt k [] i = (mempty, PWildcard mempty) | 192 | mkPatt k [] i = (mempty, PWildcard mempty) |
193 | -- mkPatt k ps' i = error $ "mkPatt " ++ show i_ ++ ": " ++ maybe "" showSI si ++ "\n" ++ show ps' ++ "\n" ++ show ps_ | 193 | -- mkPatt k ps' i = error $ "mkPatt " ++ show i_ ++ ": " ++ maybe "" showSI si ++ "\n" ++ show ps' ++ "\n" ++ show ps_ |
@@ -280,7 +280,7 @@ compilePatts ps = buildNode guardNode' n ps [n-1, n-2..0] | |||
280 | where | 280 | where |
281 | n = length ps | 281 | n = length ps |
282 | 282 | ||
283 | compileGuardTree :: MonadWriter [ParseCheck] m => (SExp -> SExp) -> (SExp -> SExp) -> Maybe SI -> [(Visibility, SExp)] -> GuardTrees -> m SExp | 283 | compileGuardTree :: MonadWriter [ParseCheck] m => (SExp -> SExp) -> (SExp -> SExp) -> Maybe SIName -> [(Visibility, SExp)] -> GuardTrees -> m SExp |
284 | compileGuardTree ulend lend si vt = fmap (\e -> foldr (uncurry SLam) e vt) . runPMC si vt . guardTreeToCases [] | 284 | compileGuardTree ulend lend si vt = fmap (\e -> foldr (uncurry SLam) e vt) . runPMC si vt . guardTreeToCases [] |
285 | where | 285 | where |
286 | guardTreeToCases :: CasePath -> GuardTrees -> PMC SExp | 286 | guardTreeToCases :: CasePath -> GuardTrees -> PMC SExp |
@@ -292,10 +292,8 @@ compileGuardTree ulend lend si vt = fmap (\e -> foldr (uncurry SLam) e vt) . run | |||
292 | return $ ulend $ SBuiltin "undefined" | 292 | return $ ulend $ SBuiltin "undefined" |
293 | In (GTSuccess e) -> do | 293 | In (GTSuccess e) -> do |
294 | tell $ (,) mempty $ maybeToList $ getRange $ sourceInfo e | 294 | tell $ (,) mempty $ maybeToList $ getRange $ sourceInfo e |
295 | --trace (ppShow $ sourceInfo e) $ | ||
296 | return $ lend e | 295 | return $ lend e |
297 | ts@(In (GuardNode f (s, cn) _ _ _)) -> case cn of | 296 | ts@(In (GuardNode f (s, cn) _ _ _)) -> case cn of |
298 | -- Nothing -> throwError sn | ||
299 | Left ((casename, inum), cns) -> do | 297 | Left ((casename, inum), cns) -> do |
300 | cf <- sequence [ iterateN n SLamV <$> guardTreeToCases (Just (cn, n, f): path) (filterGuardTree (up n f) cn 0 n $ rUp n 0 ts) | 298 | cf <- sequence [ iterateN n SLamV <$> guardTreeToCases (Just (cn, n, f): path) (filterGuardTree (up n f) cn 0 n $ rUp n 0 ts) |
301 | | (cn, n) <- cns ] | 299 | | (cn, n) <- cns ] |
@@ -339,8 +337,8 @@ compileGuardTrees ulend si vt = compileGuardTree ulend SRHS si vt . mconcat | |||
339 | compileGuardTrees' si vt = fmap (foldr1 $ SAppV2 $ SBuiltin "parEval" `SAppV` Wildcard SType) . mapM (compileGuardTrees id Nothing vt . (:[])) | 337 | compileGuardTrees' si vt = fmap (foldr1 $ SAppV2 $ SBuiltin "parEval" `SAppV` Wildcard SType) . mapM (compileGuardTrees id Nothing vt . (:[])) |
340 | 338 | ||
341 | compileCase x cs | 339 | compileCase x cs |
342 | = (`SAppV` x) <$> compileGuardTree id id (Just $ sourceInfo x) [(Visible, Wildcard SType)] (mconcat [compilePatts [p] e | (p, e) <- cs]) | 340 | = (`SAppV` x) <$> compileGuardTree id id (Just $ SIName (sourceInfo x) "") [(Visible, Wildcard SType)] (mconcat [compilePatts [p] e | (p, e) <- cs]) |
343 | 341 | ||
344 | patLam :: MonadWriter [ParseCheck] m => (SExp -> SExp) -> (Visibility, SExp) -> ParPat -> SExp -> m SExp | 342 | patLam :: MonadWriter [ParseCheck] m => (SExp -> SExp) -> (Visibility, SExp) -> ParPat -> SExp -> m SExp |
345 | patLam f vt p e = compileGuardTree f f (Just $ sourceInfo p) [vt] (compilePatts [p] $ noGuards e) | 343 | patLam f vt p e = compileGuardTree f f (Just $ SIName (sourceInfo p) "") [vt] (compilePatts [p] $ noGuards e) |
346 | 344 | ||
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs index 7aba8f77..204a9547 100644 --- a/src/LambdaCube/Compiler/Pretty.hs +++ b/src/LambdaCube/Compiler/Pretty.hs | |||
@@ -18,6 +18,7 @@ import Data.String | |||
18 | import Data.Char | 18 | import Data.Char |
19 | --import qualified Data.Set as Set | 19 | --import qualified Data.Set as Set |
20 | --import qualified Data.Map as Map | 20 | --import qualified Data.Map as Map |
21 | import Control.Applicative | ||
21 | import Control.Monad.Identity | 22 | import Control.Monad.Identity |
22 | import Control.Monad.Reader | 23 | import Control.Monad.Reader |
23 | import Control.Monad.State | 24 | import Control.Monad.State |
@@ -239,7 +240,7 @@ renderDoc | |||
239 | isAlph c = isAlphaNum c || c `elem` ("'_" :: String) | 240 | isAlph c = isAlphaNum c || c `elem` ("'_" :: String) |
240 | isOpen c = c `elem` ("({[" :: String) | 241 | isOpen c = c `elem` ("({[" :: String) |
241 | isClose c = c `elem` (")}]" :: String) | 242 | isClose c = c `elem` (")}]" :: String) |
242 | graphicChar = (`elem` ("#<>!.:^&@|-+*/\\~%=$" :: String)) | 243 | --graphicChar = (`elem` ("#<>!.:^&@|-+*/\\~%=$" :: String)) |
243 | 244 | ||
244 | -------------------------------------------------------------------------- combinators | 245 | -------------------------------------------------------------------------- combinators |
245 | 246 | ||
@@ -253,6 +254,7 @@ onblue = DFormat P.ondullblue | |||
253 | underline = DFormat P.underline | 254 | underline = DFormat P.underline |
254 | 255 | ||
255 | -- add wl-pprint combinators as necessary here | 256 | -- add wl-pprint combinators as necessary here |
257 | hardline = dZero P.hardline | ||
256 | (<+>) = dTwo (P.<+>) | 258 | (<+>) = dTwo (P.<+>) |
257 | (</>) = dTwo (P.</>) | 259 | (</>) = dTwo (P.</>) |
258 | (<$$>) = dTwo (P.<$$>) | 260 | (<$$>) = dTwo (P.<$$>) |
@@ -262,6 +264,7 @@ sep = dList P.sep | |||
262 | hsep = dList P.hsep | 264 | hsep = dList P.hsep |
263 | vcat = dList P.vcat | 265 | vcat = dList P.vcat |
264 | 266 | ||
267 | dZero x = DDocOp (const x) (Const ()) | ||
265 | dOne f = DDocOp (f . runIdentity) . Identity | 268 | dOne f = DDocOp (f . runIdentity) . Identity |
266 | dTwo f x y = DDocOp (\(Two x y) -> f x y) (Two x y) | 269 | dTwo f x y = DDocOp (\(Two x y) -> f x y) (Two x y) |
267 | dList f = DDocOp f | 270 | dList f = DDocOp f |
@@ -292,8 +295,6 @@ pattern DParen x = DPar "(" x ")" | |||
292 | pattern DBrace x = DPar "{" x "}" | 295 | pattern DBrace x = DPar "{" x "}" |
293 | pattern DOp s f l r = DInfix f l (SimpleAtom s) r | 296 | pattern DOp s f l r = DInfix f l (SimpleAtom s) r |
294 | pattern DOp0 s f = DOp s f (DText "") (DText "") | 297 | pattern DOp0 s f = DOp s f (DText "") (DText "") |
295 | --pattern DOpL s f x = DOp s f x (DText "") | ||
296 | --pattern DOpR s f x = DOp s f (DText "") x | ||
297 | pattern DSep p a b = DOp " " p a b | 298 | pattern DSep p a b = DOp " " p a b |
298 | pattern DGlue p a b = DOp "" p a b | 299 | pattern DGlue p a b = DOp "" p a b |
299 | 300 | ||
@@ -302,8 +303,6 @@ pattern DArr x y = DArr_ "->" x y | |||
302 | braces = DBrace | 303 | braces = DBrace |
303 | parens = DParen | 304 | parens = DParen |
304 | 305 | ||
305 | --dApp (DOp0 s f) x = DOpL s f x | ||
306 | --dApp (DOpL s f x) y = DOp s f x y | ||
307 | dApp x y = DApp x y | 306 | dApp x y = DApp x y |
308 | 307 | ||
309 | shCstr = DCstr | 308 | shCstr = DCstr |
diff --git a/src/LambdaCube/Compiler/Statements.hs b/src/LambdaCube/Compiler/Statements.hs index 2112dd69..c9dfa1f7 100644 --- a/src/LambdaCube/Compiler/Statements.hs +++ b/src/LambdaCube/Compiler/Statements.hs | |||
@@ -75,7 +75,7 @@ compileStmt' ds = fmap concat . sequence $ map (compileStmt (compileGuardTrees S | |||
75 | h (FunAlt n _ _) (FunAlt m _ _) = m == n | 75 | h (FunAlt n _ _) (FunAlt m _ _) = m == n |
76 | h _ _ = False | 76 | h _ _ = False |
77 | 77 | ||
78 | compileStmt :: MonadWriter [ParseCheck] m => (SI -> [(Visibility, SExp)] -> [GuardTrees] -> m SExp) -> [PreStmt] -> [PreStmt] -> m [Stmt] | 78 | compileStmt :: MonadWriter [ParseCheck] m => (SIName -> [(Visibility, SExp)] -> [GuardTrees] -> m SExp) -> [PreStmt] -> [PreStmt] -> m [Stmt] |
79 | compileStmt compilegt ds = \case | 79 | compileStmt compilegt ds = \case |
80 | [Instance{}] -> return [] | 80 | [Instance{}] -> return [] |
81 | [Class n ps ms] -> do | 81 | [Class n ps ms] -> do |
@@ -106,7 +106,7 @@ compileStmt compilegt ds = \case | |||
106 | | num == 0 && length gs > 1 -> fail $ "redefined " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd <$> gs) | 106 | | num == 0 && length gs > 1 -> fail $ "redefined " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd <$> gs) |
107 | | n `elem` [n' | TypeFamily n' _ <- ds] -> return [] | 107 | | n `elem` [n' | TypeFamily n' _ <- ds] -> return [] |
108 | | otherwise -> do | 108 | | otherwise -> do |
109 | cf <- compilegt (mconcat [sourceInfo n | FunAlt n _ _ <- fs]) vs [gt | FunAlt _ _ gt <- fs] | 109 | cf <- compilegt (SIName_ (mconcat [sourceInfo n | FunAlt n _ _ <- fs]) (getFixity n) $ sName n) vs [gt | FunAlt _ _ gt <- fs] |
110 | return [Let n (listToMaybe [t | TypeAnn n' t <- ds, n' == n]) cf] | 110 | return [Let n (listToMaybe [t | TypeAnn n' t <- ds, n' == n]) cf] |
111 | fs -> fail $ "different number of arguments of " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd . head <$> fs) | 111 | fs -> fail $ "different number of arguments of " ++ sName n ++ ":\n" ++ show (vcat $ pShow . sourceInfo . snd . head <$> fs) |
112 | [Stmt x] -> return [x] | 112 | [Stmt x] -> return [x] |
diff --git a/src/LambdaCube/Compiler/Utils.hs b/src/LambdaCube/Compiler/Utils.hs index 78872b04..8ec2f6b0 100644 --- a/src/LambdaCube/Compiler/Utils.hs +++ b/src/LambdaCube/Compiler/Utils.hs | |||
@@ -4,6 +4,7 @@ | |||
4 | {-# LANGUAGE FlexibleInstances #-} | 4 | {-# LANGUAGE FlexibleInstances #-} |
5 | {-# LANGUAGE UndecidableInstances #-} | 5 | {-# LANGUAGE UndecidableInstances #-} |
6 | {-# LANGUAGE MultiParamTypeClasses #-} | 6 | {-# LANGUAGE MultiParamTypeClasses #-} |
7 | {-# OPTIONS_GHC -fno-warn-orphans #-} | ||
7 | module LambdaCube.Compiler.Utils where | 8 | module LambdaCube.Compiler.Utils where |
8 | 9 | ||
9 | import qualified Data.IntSet as IS | 10 | import qualified Data.IntSet as IS |