@@ -25,9 +25,8 @@ module Language.PureScript.Sugar.TypeDeclarations (
25#if __GLASGOW_HASKELL__ < 710
25#if __GLASGOW_HASKELL__ < 710
26import Control.Applicative
26import Control.Applicative
28−import Control.Monad (forM, when)
28+import Control.Monad (forM)
29import Control.Monad.Error.Class (MonadError(..))
29import Control.Monad.Error.Class (MonadError(..))
30−import Control.Monad.Writer.Class (MonadWriter(tell))
32import Language.PureScript.Crash
31import Language.PureScript.Crash
33import Language.PureScript.AST
32import Language.PureScript.AST
@@ -39,19 +38,19 @@ import Language.PureScript.Traversals
40-- Replace all top level type declarations in a module with type annotations
39-- Replace all top level type declarations in a module with type annotations
42−desugarTypeDeclarationsModule :: forall m. (Functor m, Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [Module] -> m [Module]
41+desugarTypeDeclarationsModule :: forall m. (Functor m, Applicative m, MonadError MultipleErrors m) => [Module] -> m [Module]
43desugarTypeDeclarationsModule ms = forM ms $ \(Module ss coms name ds exps) ->
42desugarTypeDeclarationsModule ms = forM ms $ \(Module ss coms name ds exps) ->
44 rethrow (addHint (ErrorInModule name)) $
43 rethrow (addHint (ErrorInModule name)) $
45− Module ss coms name <$> desugarTypeDeclarations True ds <*> pure exps
44+ Module ss coms name <$> desugarTypeDeclarations ds <*> pure exps
48− desugarTypeDeclarations :: Bool -> [Declaration] -> m [Declaration]
47+ desugarTypeDeclarations :: [Declaration] -> m [Declaration]
49− desugarTypeDeclarations reqd (PositionedDeclaration pos com d : ds) = do
48+ desugarTypeDeclarations (PositionedDeclaration pos com d : ds) = do
50− (d' : ds') <- rethrowWithPosition pos $ desugarTypeDeclarations reqd (d : ds)
49+ (d' : ds') <- rethrowWithPosition pos $ desugarTypeDeclarations (d : ds)
51 return (PositionedDeclaration pos com d' : ds')
50 return (PositionedDeclaration pos com d' : ds')
52− desugarTypeDeclarations reqd (TypeDeclaration name ty : d : rest) = do
51+ desugarTypeDeclarations (TypeDeclaration name ty : d : rest) = do
53 (_, nameKind, val) <- fromValueDeclaration d
52 (_, nameKind, val) <- fromValueDeclaration d
54− desugarTypeDeclarations reqd (ValueDeclaration name nameKind [] (Right (TypedValue True val ty)) : rest)
53+ desugarTypeDeclarations (ValueDeclaration name nameKind [] (Right (TypedValue True val ty)) : rest)
56 fromValueDeclaration :: Declaration -> m (Ident, NameKind, Expr)
55 fromValueDeclaration :: Declaration -> m (Ident, NameKind, Expr)
57 fromValueDeclaration (ValueDeclaration name' nameKind [] (Right val)) | name == name' = return (name', nameKind, val)
56 fromValueDeclaration (ValueDeclaration name' nameKind [] (Right val)) | name == name' = return (name', nameKind, val)
@@ -59,19 +58,14 @@ desugarTypeDeclarationsModule ms = forM ms $ \(Module ss coms name ds exps) ->
59 (ident, nameKind, val) <- rethrowWithPosition pos $ fromValueDeclaration d'
58 (ident, nameKind, val) <- rethrowWithPosition pos $ fromValueDeclaration d'
60 return (ident, nameKind, PositionedValue pos com val)
59 return (ident, nameKind, PositionedValue pos com val)
61 fromValueDeclaration _ = throwError . errorMessage $ OrphanTypeDeclaration name
60 fromValueDeclaration _ = throwError . errorMessage $ OrphanTypeDeclaration name
62− desugarTypeDeclarations _ [TypeDeclaration name _] = throwError . errorMessage $ OrphanTypeDeclaration name
61+ desugarTypeDeclarations [TypeDeclaration name _] = throwError . errorMessage $ OrphanTypeDeclaration name
63− desugarTypeDeclarations reqd (ValueDeclaration name nameKind bs val : rest) = do
62+ desugarTypeDeclarations (ValueDeclaration name nameKind bs val : rest) = do
64− -- At the top level, match a type signature or emit a warning.
65− when reqd $ case val of
66− Right TypedValue{} -> return ()
67− Left _ -> internalError "desugarTypeDeclarations: cases were not desugared"
68− _ -> tell (addHint (ErrorInValueDeclaration name) $ errorMessage $ MissingTypeDeclaration name)
69 let (_, f, _) = everywhereOnValuesTopDownM return go return
63 let (_, f, _) = everywhereOnValuesTopDownM return go return
70 f' (Left gs) = Left <$> mapM (pairM return f) gs
64 f' (Left gs) = Left <$> mapM (pairM return f) gs
71 f' (Right v) = Right <$> f v
65 f' (Right v) = Right <$> f v
72− (:) <$> (ValueDeclaration name nameKind bs <$> f' val) <*> desugarTypeDeclarations reqd rest
66+ (:) <$> (ValueDeclaration name nameKind bs <$> f' val) <*> desugarTypeDeclarations rest
74− go (Let ds val') = Let <$> desugarTypeDeclarations False ds <*> pure val'
68+ go (Let ds val') = Let <$> desugarTypeDeclarations ds <*> pure val'
75 go other = return other
69 go other = return other
76− desugarTypeDeclarations reqd (d:ds) = (:) d <$> desugarTypeDeclarations reqd ds
70+ desugarTypeDeclarations (d:ds) = (:) d <$> desugarTypeDeclarations ds
77− desugarTypeDeclarations _ [] = return []
71+ desugarTypeDeclarations [] = return []