@@ -21,17 +21,16 @@ import qualified AST.Variable as V
21import qualified Transform.Expression as Expr
21import qualified Transform.Expression as Expr
22import qualified Type.Type as TT
22import qualified Type.Type as TT
23import qualified Type.State as TS
23import qualified Type.State as TS
24−import qualified Type.Alias as Alias
26throw :: [Doc] -> Either [Doc] a
25throw :: [Doc] -> Either [Doc] a
27throw err = Left [ P.vcat err ]
26throw err = Left [ P.vcat err ]
29−mainType :: Alias.Rules -> TS.Env -> IO (Either [P.Doc] (Map.Map String ST.CanonicalType))
28+mainType :: TS.Env -> IO (Either [P.Doc] (Map.Map String ST.CanonicalType))
30−mainType aliasRules environment =
29+mainType environment =
31− mainCheck aliasRules <$> Traverse.traverse TT.toSrcType environment
30+ mainCheck <$> Traverse.traverse TT.toSrcType environment
33− mainCheck :: Alias.Rules -> Map.Map String ST.CanonicalType -> Either [P.Doc] (Map.Map String ST.CanonicalType)
32+ mainCheck :: Map.Map String ST.CanonicalType -> Either [P.Doc] (Map.Map String ST.CanonicalType)
34− mainCheck rules env =
33+ mainCheck env =
35 case Map.lookup "main" env of
34 case Map.lookup "main" env of
36 Nothing -> Right env
35 Nothing -> Right env
37 Just typeOfMain
36 Just typeOfMain
@@ -41,16 +40,16 @@ mainType aliasRules environment =
41 acceptable = [ "Graphics.Element.Element"
40 acceptable = [ "Graphics.Element.Element"
42 , "Signal.Signal Graphics.Element.Element" ]
41 , "Signal.Signal Graphics.Element.Element" ]
44− tipe = PP.renderPretty $ Alias.canonicalRealias (fst rules) typeOfMain
43+ tipe = PP.renderPretty typeOfMain
45 err = [ P.text "Type Error: 'main' must have type Element or (Signal Element)."
44 err = [ P.text "Type Error: 'main' must have type Element or (Signal Element)."
46 , P.text "Instead 'main' has type:\n"
45 , P.text "Instead 'main' has type:\n"
47− , P.nest 4 . PP.pretty $ Alias.realias rules typeOfMain
46+ , P.nest 4 (PP.pretty typeOfMain)
48 , P.text " " ]
47 , P.text " " ]
50data Direction = In | Out
49data Direction = In | Out
52−portTypes :: Alias.Rules -> Canonical.Expr -> Either [P.Doc] ()
51+portTypes :: Canonical.Expr -> Either [P.Doc] ()
53−portTypes rules expr =
52+portTypes expr =
54 const () <$> Expr.checkPorts (check In) (check Out) expr
53 const () <$> Expr.checkPorts (check In) (check Out) expr
56 check = isValid True False False
55 check = isValid True False False
@@ -111,7 +110,7 @@ portTypes rules expr =
111 [ txt [ "Type Error: the value ", dir "coming in" "sent out"
110 [ txt [ "Type Error: the value ", dir "coming in" "sent out"
112 , " through port '", name, "' is invalid." ]
111 , " through port '", name, "' is invalid." ]
113 , txt [ "It contains ", kind, ":\n" ]
112 , txt [ "It contains ", kind, ":\n" ]
114− , (P.nest 4 . PP.pretty $ Alias.realias rules tipe) <> P.text "\n"
113+ , P.nest 4 (PP.pretty tipe) <> P.text "\n"
115 , txt [ "Acceptable values for ", dir "incoming" "outgoing", " ports include:" ]
114 , txt [ "Acceptable values for ", dir "incoming" "outgoing", " ports include:" ]
116 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples," ]
115 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples," ]
117 , txt [ " Json.Values, ", dir "" "first-order functions, ", "and concrete records." ]
116 , txt [ " Json.Values, ", dir "" "first-order functions, ", "and concrete records." ]
@@ -131,17 +130,16 @@ occurs (name, variable) =
131 desc <- liftIO $ UF.descriptor var
130 desc <- liftIO $ UF.descriptor var
132 case TT.structure desc of
131 case TT.structure desc of
133 Nothing ->
132 Nothing ->
134− modify $ \s -> s { TS.sErrors = fallback : TS.sErrors s }
133+ modify $ \s -> s { TS.sErrors = P.text msg : TS.sErrors s }
135 Just _ ->
134 Just _ ->
136 do liftIO $ UF.setDescriptor var (desc { TT.structure = Nothing })
135 do liftIO $ UF.setDescriptor var (desc { TT.structure = Nothing })
137 var' <- liftIO $ UF.fresh desc
136 var' <- liftIO $ UF.fresh desc
138 TS.addError (A.None (P.text name)) (Just msg) var var'
137 TS.addError (A.None (P.text name)) (Just msg) var var'
140 msg = "Infinite types are not allowed"
139 msg = "Infinite types are not allowed"
141− fallback _ = return $ P.text msg
143 infiniteVars :: [TT.Variable] -> TT.Variable -> IO [TT.Variable]
141 infiniteVars :: [TT.Variable] -> TT.Variable -> IO [TT.Variable]
144− infiniteVars seen var =
142+ infiniteVars seen var =
145 let go = infiniteVars (var:seen) in
143 let go = infiniteVars (var:seen) in
146 if var `elem` seen
144 if var `elem` seen
147 then return [var]
145 then return [var]