@@ -4,7 +4,7 @@
4successfully. At that point we still need to do occurs checks and ensure that
4successfully. At that point we still need to do occurs checks and ensure that
5`main` has an acceptable type.
5`main` has an acceptable type.
7−module Type.ExtraChecks (mainType, occurs) where
7+module Type.ExtraChecks (effectTypes, occurs) where
9import Prelude hiding (maybe)
9import Prelude hiding (maybe)
10import Control.Applicative ((<$>),(<*>))
10import Control.Applicative ((<$>),(<*>))
@@ -24,28 +24,32 @@ import qualified Type.Type as TT
24import qualified Type.State as TS
24import qualified Type.State as TS
27−-- MAIN TYPE
27+-- EFFECT TYPE CHECKS
29−mainType :: TS.Env -> ErrorT [P.Doc] IO (Map.Map String ST.CanonicalType)
29+effectTypes :: TS.Env -> ErrorT [P.Doc] IO (Map.Map String ST.CanonicalType)
30−mainType environment =
30+effectTypes environment =
31 do environment' <- liftIO $ Traverse.traverse TT.toSrcType environment
31 do environment' <- liftIO $ Traverse.traverse TT.toSrcType environment
32 mainCheck environment'
32 mainCheck environment'
33+ performCheck environment'
36 :: (Monad m)
40 :: (Monad m)
37 => Map.Map String ST.CanonicalType
41 => Map.Map String ST.CanonicalType
38− -> ErrorT [P.Doc] m (Map.Map String ST.CanonicalType)
42+ -> ErrorT [P.Doc] m ()
39mainCheck env =
43mainCheck env =
40 case Map.lookup "main" env of
44 case Map.lookup "main" env of
41 Nothing ->
45 Nothing ->
42− return env
46+ return ()
44 Just typeOfMain ->
48 Just typeOfMain ->
45 let tipe = ST.deepDealias typeOfMain
49 let tipe = ST.deepDealias typeOfMain
47 if tipe `elem` validMainTypes
51 if tipe `elem` validMainTypes
48− then return env
52+ then return ()
49 else throwError [ badMainMessage typeOfMain ]
53 else throwError [ badMainMessage typeOfMain ]
@@ -107,6 +111,39 @@ badMainMessage typeOfMain =
118+ => Map.Map String ST.CanonicalType
119+ -> ErrorT [P.Doc] m ()
121+ let check (name, tipe) =
122+ case Var.fromEffectName name of
127+ case ST.deepDealias tipe of
128+ ST.App (ST.Type task) [_, _]
129+ | Var.isTask task ->
132+ throwError [ badPerformMessage lineNumber tipe ]
134+ mapM_ check (Map.toList env)
137+badPerformMessage :: String -> ST.CanonicalType -> P.Doc
138+badPerformMessage lineNumber tipe =
140+ [ P.text $ "Type Error: the 'perform' declaration on line " ++ lineNumber
141+ , P.text "It must have type Task, but instead it has type:\n"
142+ , P.nest 4 (PP.pretty tipe)
110-- INFINITE TYPES
147-- INFINITE TYPES
112occurs :: (String, TT.Variable) -> StateT TS.SolverState IO ()
149occurs :: (String, TT.Variable) -> StateT TS.SolverState IO ()