@@ -1,4 +1,4 @@
1−module Transform.Canonicalize.Wire (checkInput, checkOutput, loopback) where
1+module Transform.Canonicalize.Wire (checkForeignInput, checkForeignOutput, input) where
22
33import Control.Applicative ((<$>))
44import Control.Monad.Error (forM_, throwError)
@@ -17,45 +17,45 @@ throw err =
1717 throwError [ P.vcat err ]
1818
1919
20−checkInput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
21−checkInput name tipe =
22− checkWire In name tipe tipe
20+checkForeignInput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
21+checkForeignInput name tipe =
22+ checkForeign In name tipe tipe
2323
2424
25−checkOutput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
26−checkOutput name tipe =
27− checkWire Out name tipe tipe
25+checkForeignOutput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
26+checkForeignOutput name tipe =
27+ checkForeign Out name tipe tipe
2828
2929
3030data Direction = In | Out
3131
3232
33−checkWire
33+checkForeign
3434 :: Direction
3535 -> String
3636 -> ST.CanonicalType
3737 -> ST.CanonicalType
3838 -> Env.Canonicalizer [P.Doc] ()
39−checkWire direction name rootType tipe =
39+checkForeign direction name rootType tipe =
4040 case tipe of
4141 ST.Aliased _ args t ->
42− checkWire direction name rootType (ST.dealias args t)
42+ checkForeign direction name rootType (ST.dealias args t)
4343
4444 ST.App (ST.Type signal) [t]
4545 | Var.isStream signal ->
46− validWireType False (Just Stream) direction name rootType t
46+ validForeignType False (Just Stream) direction name rootType t
4747
4848 | Var.isVarying signal ->
49− validWireType False (Just Varying) direction name rootType t
49+ validForeignType False (Just Varying) direction name rootType t
5050
5151 _ ->
52− validWireType False Nothing direction name rootType tipe
52+ validForeignType False Nothing direction name rootType tipe
5353
5454
5555data Signal = Stream | Varying
5656
5757
58−validWireType
58+validForeignType
5959 :: Bool
6060 -> Maybe Signal
6161 -> Direction
@@ -63,12 +63,12 @@ validWireType
6363 -> ST.CanonicalType
6464 -> ST.CanonicalType
6565 -> Env.Canonicalizer [P.Doc] ()
66−validWireType seenFunc seenSignal direction name rootType tipe =
66+validForeignType seenFunc seenSignal direction name rootType tipe =
6767 let valid localType =
68− validWireType seenFunc seenSignal direction name rootType localType
68+ validForeignType seenFunc seenSignal direction name rootType localType
6969
7070 err kind =
71− throw (wireError name direction rootType tipe kind)
71+ throw (foreignError name direction rootType tipe kind)
7272 in
7373 case tipe of
7474 ST.Aliased _ args t ->
@@ -112,7 +112,7 @@ validWireType seenFunc seenSignal direction name rootType tipe =
112112
113113 Nothing ->
114114 forM_ (ST.collectLambdas tipe)
115− (validWireType True seenSignal direction name rootType)
115+ (validForeignType True seenSignal direction name rootType)
116116
117117 ST.Record _ (Just _) ->
118118 err "It contains extended records with free type variables"
@@ -121,22 +121,22 @@ validWireType seenFunc seenSignal direction name rootType tipe =
121121 mapM_ (\(k,v) -> (,) k <$> valid v) fields
122122
123123
124−wireError
124+foreignError
125125 :: String
126126 -> Direction
127127 -> ST.CanonicalType
128128 -> ST.CanonicalType
129129 -> String
130130 -> [P.Doc]
131−wireError name direction rootType localType problemMessage =
132− [ P.text (dir "Input" "Output" ++ " Error:")
131+foreignError name direction rootType localType problemMessage =
132+ [ P.text ("Foreign " ++ dir "Input" "Output" ++ " Error:")
133133 , P.nest 4 $
134134 P.vcat
135− [ txt [ "The ", wire, " named '", name, "' has an invalid type.\n" ]
135+ [ txt [ "The foreign ", wire, " named '", name, "' has an invalid type.\n" ]
136136 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
137137 , txt [ problemMessage, ":\n" ]
138138 , 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:" ]
140140 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, unit values," ]
141141 , txt [ " Json.Values, ", dir "" "first-order functions, promises, ", "and concrete records." ]
142142 ]
@@ -153,12 +153,12 @@ wireError name direction rootType localType problemMessage =
153153 dir "input" "output"
154154
155155
156−loopback
156+input
157157 :: String
158158 -> Maybe Canonical.Expr
159159 -> ST.CanonicalType
160160 -> Env.Canonicalizer [P.Doc] D.CanonicalLoopback
161−loopback name maybeExpr tipe =
161+input name maybeExpr tipe =
162162 case maybeExpr of
163163 Nothing ->
164164 case ST.deepDealias tipe of
@@ -168,12 +168,12 @@ loopback name maybeExpr tipe =
168168 ]
169169 Nothing
170170 | Var.isStream stream && Var.isAddress address && a == b ->
171− return (D.Mailbox name tipe)
171+ return (D.Address name tipe)
172172
173173
174174 _ ->
175− throw $ loopbackError name tipe $
176− [ P.text "A loopback like this must be a Mailbox." ]
175+ throw $ inputError name tipe $
176+ [ P.text "An input like this must be a Stream.Input" ]
177177
178178 Just expr ->
179179 case ST.deepDealias tipe of
@@ -187,20 +187,20 @@ loopback name maybeExpr tipe =
187187 return (D.Promise name promiseType expr tipe)
188188
189189 _ ->
190− throw $ loopbackError name tipe $
191− [ P.text "A loopback that runs promises must be a stream of results."
190+ throw $ inputError name tipe $
191+ [ P.text "An input that runs promises must be a stream of results."
192192 , P.text "Something like the following:\n"
193193 , P.text " Stream (Result Http.Error String)"
194194 , P.text " Stream (Result x ())"
195195 ]
196196
197197
198−loopbackError :: String -> ST.CanonicalType -> [Doc] -> [Doc]
199−loopbackError name tipe message =
200− [ P.text "Loopback Error:"
198+inputError :: String -> ST.CanonicalType -> [Doc] -> [Doc]
199+inputError name tipe message =
200+ [ P.text "Input Error:"
201201 , P.nest 4 $
202202 P.vcat $
203− [ P.text ("The loopback named '" ++ name ++ "' has an invalid type.\n")
203+ [ P.text ("The input named '" ++ name ++ "' has an invalid type.\n")
204204 , P.nest 4 (PP.pretty tipe) <> P.text "\n"
205205 ]
206206 ++ message