on master help sign in
Disallow signals-of-signals, functions that involve signals, and signals of functions
commitbc6ac142ae2c77567d97e644b54a3a1de4aa8bc7 authorEvan Czaplicki <info@elm-lang.org> dateTue 14 Jan 2014, 13:28 (13 years ago) parent461abc0
1 file changed+17−10
compiler/Type/ExtraChecks.hs+17−10
compiler/Type/ExtraChecks.hs+17−10
@@ -49,20 +49,24 @@ portTypes :: Alias.Rules -> E.LExpr -> Either [P.Doc] ()
4949portTypes rules expr =
5050 const () <$> Expr.checkPorts (check In) (check Out) expr
5151 where
52− check = isValid True
53− isValid firstOrder direction name tipe =
54− let valid = isValid firstOrder direction name in
52+ check = isValid False False
53+ isValid seenFunc seenSignal direction name tipe =
54+ let valid = isValid seenFunc seenSignal direction name in
5555 case tipe of
56− T.Data ctor ts | okay ctor -> mapM_ valid ts
57− | otherwise -> err "Algebraic Data Types"
56+ T.Data ctor ts
57+ | isJs ctor || isElm ctor -> mapM_ valid ts
58+ | ctor == "Signal.Signal" -> handleSignal ts
59+ | otherwise -> err "Algebraic Data Types"
5860
5961 T.Var _ -> err "free type variables"
6062
6163 T.Lambda _ _ ->
6264 case direction of
6365 In -> err "functions"
64− Out | firstOrder -> mapM_ (isValid False direction name) (T.collectLambdas tipe)
65− | otherwise -> err "higher-order functions"
66+ Out | seenFunc -> err "higher-order functions"
67+ | seenSignal -> err "signals that contain functions"
68+ | otherwise ->
69+ mapM_ (isValid True seenSignal direction name) (T.collectLambdas tipe)
6670
6771 T.Record _ (Just _) -> err "extended records with free type variables"
6872
@@ -70,16 +74,19 @@ portTypes rules expr =
7074 mapM_ (\(k,v) -> (,) k <$> valid v) fields
7175
7276 where
73− okay ctor = isJs ctor || isElm ctor
74−
7577 isJs ctor =
7678 List.isPrefixOf "JavaScript." ctor
7779 && length (filter (=='.') ctor) == 1
7880
7981 isElm ctor =
80− ctor `elem` ["Int","Float","String","Bool","Maybe.Maybe","_List","Signal.Signal"]
82+ ctor `elem` ["Int","Float","String","Bool","Maybe.Maybe","_List"]
8183 || Help.isTuple ctor
8284
85+ handleSignal ts
86+ | seenFunc = err "functions that involve signals"
87+ | seenSignal = err "signals-of-signals"
88+ | otherwise = mapM_ (isValid seenFunc True direction name) ts
89+
8390 dir inMsg outMsg = case direction of { In -> inMsg ; Out -> outMsg }
8491 txt = P.text . concat
8592