@@ -1,4 +1,4 @@
1−module Transform.Canonicalize.Wire (checkInput, checkOutput, loopback) where
1+module Transform.Canonicalize.Wire (checkForeignInput, checkForeignOutput, input) where
3import Control.Applicative ((<$>))
3import Control.Applicative ((<$>))
4import Control.Monad.Error (forM_, throwError)
4import Control.Monad.Error (forM_, throwError)
@@ -17,45 +17,45 @@ throw err =
17 throwError [ P.vcat err ]
17 throwError [ P.vcat err ]
20−checkInput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
20+checkForeignInput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
21−checkInput name tipe =
21+checkForeignInput name tipe =
22− checkWire In name tipe tipe
22+ checkForeign In name tipe tipe
25−checkOutput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
25+checkForeignOutput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
26−checkOutput name tipe =
26+checkForeignOutput name tipe =
27− checkWire Out name tipe tipe
27+ checkForeign Out name tipe tipe
30data Direction = In | Out
30data Direction = In | Out
33−checkWire
33+checkForeign
34 :: Direction
34 :: Direction
36 -> ST.CanonicalType
36 -> ST.CanonicalType
37 -> ST.CanonicalType
37 -> ST.CanonicalType
38 -> Env.Canonicalizer [P.Doc] ()
38 -> Env.Canonicalizer [P.Doc] ()
39−checkWire direction name rootType tipe =
39+checkForeign direction name rootType tipe =
40 case tipe of
40 case tipe of
41 ST.Aliased _ args t ->
41 ST.Aliased _ args t ->
42− checkWire direction name rootType (ST.dealias args t)
42+ checkForeign direction name rootType (ST.dealias args t)
44 ST.App (ST.Type signal) [t]
44 ST.App (ST.Type signal) [t]
45 | Var.isStream signal ->
45 | Var.isStream signal ->
46− validWireType False (Just Stream) direction name rootType t
46+ validForeignType False (Just Stream) direction name rootType t
48 | Var.isVarying signal ->
48 | Var.isVarying signal ->
49− validWireType False (Just Varying) direction name rootType t
49+ validForeignType False (Just Varying) direction name rootType t
52− validWireType False Nothing direction name rootType tipe
52+ validForeignType False Nothing direction name rootType tipe
55data Signal = Stream | Varying
55data Signal = Stream | Varying
58−validWireType
58+validForeignType
60 -> Maybe Signal
60 -> Maybe Signal
61 -> Direction
61 -> Direction
@@ -63,12 +63,12 @@ validWireType
63 -> ST.CanonicalType
63 -> ST.CanonicalType
64 -> ST.CanonicalType
64 -> ST.CanonicalType
65 -> Env.Canonicalizer [P.Doc] ()
65 -> Env.Canonicalizer [P.Doc] ()
66−validWireType seenFunc seenSignal direction name rootType tipe =
66+validForeignType seenFunc seenSignal direction name rootType tipe =
67 let valid localType =
67 let valid localType =
68− validWireType seenFunc seenSignal direction name rootType localType
68+ validForeignType seenFunc seenSignal direction name rootType localType
70 err kind =
70 err kind =
71− throw (wireError name direction rootType tipe kind)
71+ throw (foreignError name direction rootType tipe kind)
73 case tipe of
73 case tipe of
74 ST.Aliased _ args t ->
74 ST.Aliased _ args t ->
@@ -112,7 +112,7 @@ validWireType seenFunc seenSignal direction name rootType tipe =
113 Nothing ->
113 Nothing ->
114 forM_ (ST.collectLambdas tipe)
114 forM_ (ST.collectLambdas tipe)
115− (validWireType True seenSignal direction name rootType)
115+ (validForeignType True seenSignal direction name rootType)
117 ST.Record _ (Just _) ->
117 ST.Record _ (Just _) ->
118 err "It contains extended records with free type variables"
118 err "It contains extended records with free type variables"
@@ -121,22 +121,22 @@ validWireType seenFunc seenSignal direction name rootType tipe =
121 mapM_ (\(k,v) -> (,) k <$> valid v) fields
121 mapM_ (\(k,v) -> (,) k <$> valid v) fields
124−wireError
124+foreignError
125 :: String
125 :: String
126 -> Direction
126 -> Direction
127 -> ST.CanonicalType
127 -> ST.CanonicalType
128 -> ST.CanonicalType
128 -> ST.CanonicalType
129 -> String
129 -> String
130 -> [P.Doc]
130 -> [P.Doc]
131−wireError name direction rootType localType problemMessage =
131+foreignError name direction rootType localType problemMessage =
132− [ P.text (dir "Input" "Output" ++ " Error:")
132+ [ P.text ("Foreign " ++ dir "Input" "Output" ++ " Error:")
133 , P.nest 4 $
133 , P.nest 4 $
135− [ txt [ "The ", wire, " named '", name, "' has an invalid type.\n" ]
135+ [ txt [ "The foreign ", wire, " named '", name, "' has an invalid type.\n" ]
136 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
136 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
137 , txt [ problemMessage, ":\n" ]
137 , txt [ problemMessage, ":\n" ]
138 , P.nest 4 (PP.pretty localType) <> P.text "\n"
138 , P.nest 4 (PP.pretty localType) <> P.text "\n"
139− , txt [ "Acceptable values for ", wire, "s include:" ]
139+ , txt [ "Acceptable values for foreign ", wire, "s include:" ]
140 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, unit values," ]
140 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, unit values," ]
141 , txt [ " Json.Values, ", dir "" "first-order functions, promises, ", "and concrete records." ]
141 , txt [ " Json.Values, ", dir "" "first-order functions, promises, ", "and concrete records." ]
@@ -153,12 +153,12 @@ wireError name direction rootType localType problemMessage =
153 dir "input" "output"
153 dir "input" "output"
157 :: String
157 :: String
158 -> Maybe Canonical.Expr
158 -> Maybe Canonical.Expr
159 -> ST.CanonicalType
159 -> ST.CanonicalType
160 -> Env.Canonicalizer [P.Doc] D.CanonicalLoopback
160 -> Env.Canonicalizer [P.Doc] D.CanonicalLoopback
161−loopback name maybeExpr tipe =
161+input name maybeExpr tipe =
162 case maybeExpr of
162 case maybeExpr of
163 Nothing ->
163 Nothing ->
164 case ST.deepDealias tipe of
164 case ST.deepDealias tipe of
@@ -168,12 +168,12 @@ loopback name maybeExpr tipe =
170 | Var.isStream stream && Var.isAddress address && a == b ->
170 | Var.isStream stream && Var.isAddress address && a == b ->
171− return (D.Mailbox name tipe)
171+ return (D.Address name tipe)
175− throw $ loopbackError name tipe $
175+ throw $ inputError name tipe $
176− [ P.text "A loopback like this must be a Mailbox." ]
176+ [ P.text "An input like this must be a Stream.Input" ]
178 Just expr ->
178 Just expr ->
179 case ST.deepDealias tipe of
179 case ST.deepDealias tipe of
@@ -187,20 +187,20 @@ loopback name maybeExpr tipe =
187 return (D.Promise name promiseType expr tipe)
187 return (D.Promise name promiseType expr tipe)
190− throw $ loopbackError name tipe $
190+ throw $ inputError name tipe $
191− [ P.text "A loopback that runs promises must be a stream of results."
191+ [ P.text "An input that runs promises must be a stream of results."
192 , P.text "Something like the following:\n"
192 , P.text "Something like the following:\n"
193 , P.text " Stream (Result Http.Error String)"
193 , P.text " Stream (Result Http.Error String)"
194 , P.text " Stream (Result x ())"
194 , P.text " Stream (Result x ())"
198−loopbackError :: String -> ST.CanonicalType -> [Doc] -> [Doc]
198+inputError :: String -> ST.CanonicalType -> [Doc] -> [Doc]
199−loopbackError name tipe message =
199+inputError name tipe message =
200− [ P.text "Loopback Error:"
200+ [ P.text "Input Error:"
201 , P.nest 4 $
201 , P.nest 4 $
203− [ P.text ("The loopback named '" ++ name ++ "' has an invalid type.\n")
203+ [ P.text ("The input named '" ++ name ++ "' has an invalid type.\n")
204 , P.nest 4 (PP.pretty tipe) <> P.text "\n"
204 , P.nest 4 (PP.pretty tipe) <> P.text "\n"
206 ++ message
206 ++ message