@@ -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, wireTypes) where
7+module Type.ExtraChecks (mainType, occurs) where
9import Prelude hiding (maybe)
9import Prelude hiding (maybe)
10import Control.Applicative ((<$>),(<*>))
10import Control.Applicative ((<$>),(<*>))
@@ -16,21 +16,14 @@ import qualified Data.UnionFind.IO as UF
16import Text.PrettyPrint as P
16import Text.PrettyPrint as P
18import qualified AST.Annotation as A
18import qualified AST.Annotation as A
19−import qualified AST.Expression.Canonical as Canonical
20import qualified AST.PrettyPrint as PP
19import qualified AST.PrettyPrint as PP
21import qualified AST.Type as ST
20import qualified AST.Type as ST
22import qualified AST.Variable as Var
21import qualified AST.Variable as Var
23−import qualified Transform.Expression as Expr
24import qualified Type.Hint as Hint
22import qualified Type.Hint as Hint
25import qualified Type.Type as TT
23import qualified Type.Type as TT
26import qualified Type.State as TS
24import qualified Type.State as TS
29−throw :: [Doc] -> Either [Doc] a
34-- MAIN TYPE
27-- MAIN TYPE
36mainType :: TS.Env -> ErrorT [P.Doc] IO (Map.Map String ST.CanonicalType)
29mainType :: TS.Env -> ErrorT [P.Doc] IO (Map.Map String ST.CanonicalType)
@@ -114,181 +107,6 @@ badMainMessage typeOfMain =
119−data Direction = In | Out
122−wireTypes :: (Monad m) => Canonical.Expr -> ErrorT [P.Doc] m ()
124− case Expr.checkWires (checkWires In) (checkWires Out) checkLoobacks expr of
125− Left err -> throwError err
126− Right _ -> return ()
129−checkWires :: Direction -> String -> ST.CanonicalType -> Either [P.Doc] ()
130−checkWires direction name tipe =
131− checkWiresHelp direction name tipe tipe
139− -> Either [P.Doc] ()
140−checkWiresHelp direction name rootType tipe =
142− ST.Aliased _ args t ->
143− checkWiresHelp direction name rootType (ST.dealias args t)
145− ST.App (ST.Type signal) [t]
146− | Var.isStream signal ->
147− validWireType False (Just Stream) direction name rootType t
149− | Var.isVarying signal ->
150− validWireType False (Just Varying) direction name rootType t
153− validWireType False Nothing direction name rootType tipe
156−data Signal = Stream | Varying
166− -> Either [P.Doc] ()
167−validWireType seenFunc seenSignal direction name rootType tipe =
168− let valid localType =
169− validWireType seenFunc seenSignal direction name rootType localType
172− throw (wireError name direction rootType tipe kind)
175− ST.Aliased _ args t ->
176− valid (ST.dealias args t)
179− case any ($ v) [ Var.isJson, Var.isPrimitive, Var.isTuple ] of
181− False -> err "It contains an unsupported type"
186− ST.App (ST.Type v) [t]
187− | Var.isMaybe v -> valid t
188− | Var.isArray v -> valid t
189− | Var.isList v -> valid t
191− ST.App (ST.Type v) ts
192− | Var.isTuple v -> mapM_ valid ts
195− err "It contains an unsupported type"
198− err "It contains a free type variable"
202− In -> err "It contains functions"
205− then err "It contains higher-order functions"
209− err "It is a streams that contains a function"
212− err "It is a varying value that contains a function"
215− forM_ (ST.collectLambdas tipe)
216− (validWireType True seenSignal direction name rootType)
218− ST.Record _ (Just _) ->
219− err "It contains extended records with free type variables"
221− ST.Record fields Nothing ->
222− mapM_ (\(k,v) -> (,) k <$> valid v) fields
232−wireError name direction rootType localType problemMessage =
233− [ P.text (dir "Input" "Output" ++ " Error:")
236− [ txt [ "The ", wire, " named '", name, "' has an invalid type.\n" ]
237− , P.nest 4 (PP.pretty rootType) <> P.text "\n"
238− , txt [ problemMessage, ":\n" ]
239− , P.nest 4 (PP.pretty localType) <> P.text "\n"
240− , txt [ "Acceptable values for ", wire, "s include:" ]
241− , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, unit values," ]
242− , txt [ " Json.Values, ", dir "" "first-order functions, promises, ", "and concrete records." ]
251− txt = P.text . concat
254− dir "input" "output"
257−checkLoobacks :: String -> ST.CanonicalType -> Bool -> Either [P.Doc] ()
258−checkLoobacks name tipe hasExpr =
259− checkLoobacksHelp name tipe tipe hasExpr
262−checkLoobacksHelp :: String -> ST.CanonicalType -> ST.CanonicalType -> Bool -> Either [P.Doc] ()
263−checkLoobacksHelp name rootType tipe hasExpr =
264− case ST.deepDealias tipe of
266− [ ("mailbox", ST.App (ST.Type mailbox) [a])
267− , ("stream", ST.App (ST.Type stream) [b])
271− && Var.isStream stream
272− && Var.isMailbox mailbox
277− ST.App (ST.Type signal) [ ST.App (ST.Type result) [_,_] ]
278− | hasExpr && Var.isStream signal && Var.isResult result ->
283− [ P.text "Loopback Error:"
286− [ P.text ("The loopback named '" ++ name ++ "' has an invalid type.\n")
287− , P.nest 4 (PP.pretty rootType) <> P.text "\n"
292-- INFINITE TYPES
110-- INFINITE TYPES
294occurs :: (String, TT.Variable) -> StateT TS.SolverState IO ()
112occurs :: (String, TT.Variable) -> StateT TS.SolverState IO ()