@@ -4,6 +4,8 @@ import Control.Applicative ((<$>))
44import Control.Monad.Error (throwError)
55import Text.PrettyPrint as P
66
7+import qualified AST.Declaration as D
8+import qualified AST.Expression.Canonical as Canonical
79import qualified AST.PrettyPrint as PP
810import qualified AST.Type as T
911import qualified AST.Variable as Var
@@ -19,46 +21,44 @@ throw err =
1921
2022check
2123 :: String
24+ -> Maybe Canonical.Expr
2225 -> T.CanonicalType
23− -> Env.Canonicalizer [P.Doc] (T.PortDirection Var.Canonical)
24−check name tipe =
25− checkHelp name tipe tipe
26+ -> Env.Canonicalizer [P.Doc] D.CanonicalPort
27+check name maybeExpr rootType =
28+ checkHelp name maybeExpr rootType rootType
2629
2730
2831checkHelp
2932 :: String
33+ -> Maybe Canonical.Expr
3034 -> T.CanonicalType
3135 -> T.CanonicalType
32− -> Env.Canonicalizer [P.Doc] (T.PortDirection Var.Canonical)
33−checkHelp name rootType tipe =
36+ -> Env.Canonicalizer [P.Doc] D.CanonicalPort
37+checkHelp name maybeExpr rootType tipe =
3438 case tipe of
35− T.Aliased alias [(_,arg)] _
36− | Var.is ["Port"] "Port" alias ->
37− return T.Internal
38−
39− | Var.is ["Port"] "InboundPort" alias ->
40− do validForeignType name In arg arg
41− return (T.Inbound arg)
39+ T.Aliased _ args t ->
40+ checkHelp name maybeExpr rootType (T.dealias args t)
4241
43− | Var.is ["Port"] "OutboundPort" alias ->
44− do validForeignType name Out arg arg
45− return (T.Outbound arg)
42+ T.App (T.Type stream) [arg]
43+ | Var.isStream stream ->
44+ case maybeExpr of
45+ Nothing ->
46+ do validForeignType name In arg arg
47+ return (D.Inbound name (T.Stream rootType arg))
4648
47− T.Aliased _ args t ->
48− checkHelp name rootType (T.dealias args t)
49+ Just expr ->
50+ do validForeignType name Out arg arg
51+ return (D.Outbound name expr (T.Stream rootType arg))
4952
5053 _ ->
51− throw $
52− [ P.text "Port Error:"
53− , P.nest 4 $
54− P.vcat $
55− [ P.text ("The port named '" ++ name ++ "' has an invalid type.\n")
56− , P.nest 4 (PP.pretty rootType) <> P.text "\n"
57− , P.text "It must be a Port.Port, Port.InboundPort, or Port.OutboundPort."
58− , P.text "See the Port module for more details:"
59− , P.text "<http://package.elm-lang.org/packages/elm-lang/core/latest/Port>"
60− ]
61− ]
54+ case maybeExpr of
55+ Nothing ->
56+ do validForeignType name In rootType tipe
57+ return (D.Inbound name (T.Normal rootType))
58+
59+ Just expr ->
60+ do validForeignType name Out rootType tipe
61+ return (D.Outbound name expr (T.Normal rootType))
6262
6363
6464-- CHECK INBOUND AND OUTBOUND TYPES
@@ -84,7 +84,7 @@ validForeignType name portKind rootType tipe =
8484 valid (T.dealias args t)
8585
8686 T.Type v ->
87− case any ($ v) [ Var.isJson, Var.isPrimitive, Var.isTuple ] of
87+ case any ($ v) [ Var.isJavaScript, Var.isPrimitive, Var.isTuple ] of
8888 True -> return ()
8989 False -> err "It contains an unsupported type"
9090
@@ -130,9 +130,9 @@ foreignError name portKind rootType localType problemMessage =
130130 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
131131 , txt [ problemMessage, ":\n" ]
132132 , P.nest 4 (PP.pretty localType) <> P.text "\n"
133− , txt [ "Acceptable values for ", port, "s include:" ]
133+ , txt [ "The kinds of values that can flow through ", port, "s include:" ]
134134 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays," ]
135− , txt [ " Tuples, unit values, Json.Values, and concrete records." ]
135+ , txt [ " Tuples, JavaScript.Values, and concrete records." ]
136136 ]
137137 ]
138138 where