@@ -4,6 +4,8 @@ import Control.Applicative ((<$>))
4import Control.Monad.Error (throwError)
4import Control.Monad.Error (throwError)
5import Text.PrettyPrint as P
5import Text.PrettyPrint as P
7+import qualified AST.Declaration as D
8+import qualified AST.Expression.Canonical as Canonical
7import qualified AST.PrettyPrint as PP
9import qualified AST.PrettyPrint as PP
8import qualified AST.Type as T
10import qualified AST.Type as T
9import qualified AST.Variable as Var
11import qualified AST.Variable as Var
@@ -19,46 +21,44 @@ throw err =
24+ -> Maybe Canonical.Expr
22 -> T.CanonicalType
25 -> T.CanonicalType
23− -> Env.Canonicalizer [P.Doc] (T.PortDirection Var.Canonical)
26+ -> Env.Canonicalizer [P.Doc] D.CanonicalPort
24−check name tipe =
27+check name maybeExpr rootType =
25− checkHelp name tipe tipe
28+ checkHelp name maybeExpr rootType rootType
33+ -> Maybe Canonical.Expr
30 -> T.CanonicalType
34 -> T.CanonicalType
31 -> T.CanonicalType
35 -> T.CanonicalType
32− -> Env.Canonicalizer [P.Doc] (T.PortDirection Var.Canonical)
36+ -> Env.Canonicalizer [P.Doc] D.CanonicalPort
33−checkHelp name rootType tipe =
37+checkHelp name maybeExpr rootType tipe =
34 case tipe of
38 case tipe of
35− T.Aliased alias [(_,arg)] _
39+ T.Aliased _ args t ->
36− | Var.is ["Port"] "Port" alias ->
40+ checkHelp name maybeExpr rootType (T.dealias args t)
39− | Var.is ["Port"] "InboundPort" alias ->
40− do validForeignType name In arg arg
41− return (T.Inbound arg)
43− | Var.is ["Port"] "OutboundPort" alias ->
42+ T.App (T.Type stream) [arg]
43+ | Var.isStream stream ->
44− do validForeignType name Out arg arg
46+ do validForeignType name In arg arg
45− return (T.Outbound arg)
47+ return (D.Inbound name (T.Stream rootType arg))
47− T.Aliased _ args t ->
49+ Just expr ->
48− checkHelp name rootType (T.dealias args t)
50+ do validForeignType name Out arg arg
51+ return (D.Outbound name expr (T.Stream rootType arg))
51− throw $
54+ case maybeExpr of
52− [ P.text "Port Error:"
55+ Nothing ->
53− , P.nest 4 $
56+ do validForeignType name In rootType tipe
54− P.vcat $
57+ return (D.Inbound name (T.Normal rootType))
55− [ P.text ("The port named '" ++ name ++ "' has an invalid type.\n")
58+
56− , P.nest 4 (PP.pretty rootType) <> P.text "\n"
59+ Just expr ->
57− , P.text "It must be a Port.Port, Port.InboundPort, or Port.OutboundPort."
60+ do validForeignType name Out rootType tipe
58− , P.text "See the Port module for more details:"
61+ return (D.Outbound name expr (T.Normal rootType))
59− , P.text "<http://package.elm-lang.org/packages/elm-lang/core/latest/Port>"
64-- CHECK INBOUND AND OUTBOUND TYPES
64-- CHECK INBOUND AND OUTBOUND TYPES
@@ -84,7 +84,7 @@ validForeignType name portKind rootType tipe =
84 valid (T.dealias args t)
84 valid (T.dealias args t)
86 T.Type v ->
86 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
88 True -> return ()
88 True -> return ()
89 False -> err "It contains an unsupported type"
89 False -> err "It contains an unsupported type"
@@ -130,9 +130,9 @@ foreignError name portKind rootType localType problemMessage =
130 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
130 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
131 , txt [ problemMessage, ":\n" ]
131 , txt [ problemMessage, ":\n" ]
132 , P.nest 4 (PP.pretty localType) <> P.text "\n"
132 , 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:" ]
134 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays," ]
134 , 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." ]