@@ -20,6 +20,7 @@ import qualified Canonicalize.Type as Type
2020import qualified Elm.Name as N
2121import qualified Reporting.Annotation as A
2222import qualified Reporting.Error.Canonicalize as Error
23+import qualified Reporting.Region as R
2324import qualified Reporting.Result as Result
2425import qualified Reporting.Warning as Warning
2526
@@ -36,8 +37,13 @@ type Result a =
3637-- CANONICALIZE
3738
3839
39−canonicalize :: Env.Env -> Map.Map N.Name a -> Valid.Effects -> Result Can.Effects
40−canonicalize env unions effects =
40+canonicalize
41+ :: Env.Env
42+ -> [A.Located Valid.Decl]
43+ -> Map.Map N.Name union
44+ -> Valid.Effects
45+ -> Result Can.Effects
46+canonicalize env decls unions effects =
4147 case effects of
4248 Valid.NoEffects ->
4349 Result.ok Can.NoEffects
@@ -46,24 +52,28 @@ canonicalize env unions effects =
4652 do pairs <- traverse (canonicalizePort env) ports
4753 return $ Can.Ports (Map.fromList pairs)
4854
49− Valid.Cmd cmdType ->
50− Can.Cmd <$> verifyEffectType cmdType unions
55+ Valid.Manager region manager ->
56+ let dict = Map.fromList (map toNameRegion decls) in
57+ Can.Manager
58+ <$> verifyManager region dict "init"
59+ <*> verifyManager region dict "onEffects"
60+ <*> verifyManager region dict "onSelfMsg"
61+ <*>
62+ case manager of
63+ Valid.Cmd cmdType ->
64+ Can.Cmd <$> verifyEffectType cmdType unions
5165
52− Valid.Sub subType ->
53− Can.Sub <$> verifyEffectType subType unions
66+ Valid.Sub subType ->
67+ Can.Sub <$> verifyEffectType subType unions
5468
55− Valid.Fx cmdType subType ->
56− Can.Fx
57− <$> verifyEffectType cmdType unions
58− <*> verifyEffectType subType unions
69+ Valid.Fx cmdType subType ->
70+ Can.Fx
71+ <$> verifyEffectType cmdType unions
72+ <*> verifyEffectType subType unions
5973
6074
61−verifyEffectType :: A.Located N.Name -> Map.Map N.Name a -> Result N.Name
62−verifyEffectType (A.A region name) unions =
63− if Map.member name unions then
64− Result.ok name
65− else
66− Result.throw region (Error.EffectNotFound name)
75+
76+-- CANONICALIZE PORT
6777
6878
6979canonicalizePort :: Env.Env -> Valid.Port -> Result (N.Name, Can.Port)
@@ -93,6 +103,33 @@ canonicalizePort env (Valid.Port (A.A region portName) tipe) =
93103
94104
95105
106+-- VERIFY MANAGER
107+
108+
109+verifyEffectType :: A.Located N.Name -> Map.Map N.Name a -> Result N.Name
110+verifyEffectType (A.A region name) unions =
111+ if Map.member name unions then
112+ Result.ok name
113+ else
114+ Result.throw region (Error.EffectNotFound name)
115+
116+
117+toNameRegion :: A.Located Valid.Decl -> (N.Name, R.Region)
118+toNameRegion (A.A _ (Valid.Decl (A.A region name) _ _ _)) =
119+ (name, region)
120+
121+
122+verifyManager :: R.Region -> Map.Map N.Name R.Region -> N.Name -> Result R.Region
123+verifyManager tagRegion decls name =
124+ case Map.lookup name decls of
125+ Just region ->
126+ Result.ok region
127+
128+ Nothing ->
129+ Result.throw tagRegion (Error.EffectFunctionNotFound name)
130+
131+
132+
96133-- CHECK PAYLOAD TYPES
97134
98135