on master help sign in
Add type hints for new libraries, and fix the types of fps and fpsWhen.
commit9f47e87bac38dd27052b9f457c123feceb736227 authorevancz <info@elm-lang.org> dateMon 14 Jan 2013, 00:15 (14 years ago) parent39e2352
2 files changed+44−15
elm/src/Types/Hints.hs+40−15 elm/src/Types/Types.hs+4
elm/src/Types/Hints.hs+40−15
@@ -168,6 +168,7 @@ signals = prefix "Signal"
168168 , "timeOf" -:: signalOf a ==> signalOf time
169169 , "merge" -:: signalOf a ==> signalOf a ==> signalOf a
170170 , "merges" -:: listOf (signalOf a) ==> signalOf a
171+ , "mergeEither" -:: signalOf a ==> signalOf b ==> signalOf (eitherOf a b)
171172 , numScheme (\n -> int ==> signalOf n ==> signalOf float) "average"
172173 ]
173174
@@ -184,9 +185,7 @@ http = prefix "HTTP"
184185 response t = ADT "Response" [t]
185186
186187concreteSignals =
187− [ "Keyboard.Raw.keysDown" -: signalOf (listOf int)
188− , "Keyboard.Raw.charPressed" -: signalOf (maybeOf int)
189− , "Random.inRange" -: int ==> int ==> signalOf int
188+ [ "Random.inRange" -: int ==> int ==> signalOf int
190189 , "Random.randomize" -:: int ==> int ==> signalOf a ==> signalOf int
191190 , "Window.dimensions" -: signalOf point
192191 , "Window.width" -: signalOf int
@@ -206,10 +205,27 @@ concreteSignals =
206205 , "Input.dropDown" -:: listOf (tupleOf [string,a]) ==> tupleOf [element, signalOf a]
207206 ]
208207
208+keyboards = prefix "Keyboard"
209+ [ "Raw.keysDown" -: signalOf (listOf int)
210+ , "Raw.charPressed" -: signalOf (maybeOf int)
211+ , "arrows" -: signalOf (recordOf [("x",int),("y",int)]))
212+ , "wasd" -: signalOf (recordOf [("x",int),("y",int)]))
213+ , "ctrl" -: signalOf bool
214+ , "space" -: signalOf bool
215+ , "shift" -: signalOf bool
216+ ]
217+
218+touches = prefix "Touch"
219+ [ "touches" -: signalOf (listOf (recordOf [("x" ,int) ,("y" ,int)
220+ ,("x0",int) ,("y0",int)
221+ ,("t0",time),("id",int)]))
222+ , "taps" -: signalOf (recordOf [("x",int),("y",int)])
223+ ]
224+
209225times = prefix "Time"
210− [ "fps" -: number ==> signalOf time
226+ [ numScheme (\n -> n ==> signalOf time) "fps"
227+ , numScheme (\n -> n ==> signalOf bool ==> signalOf time) "fpsWhen"
211228 , "every" -: time ==> signalOf time
212− , "fpsWhen" -: number ==> signalOf bool ==> signalOf time
213229 , "delay" -:: time ==> signalOf a ==> signalOf a
214230 , "since" -:: time ==> signalOf a ==> signalOf bool
215231 , "hour" -: time
@@ -303,6 +319,8 @@ funcs =
303319 , "Nil" -:: listOf a
304320 , "Just" -:: a ==> maybeOf a
305321 , "Nothing" -:: maybeOf a
322+ , "Left" -:: a ==> eitherOf a b
323+ , "Right" -:: b ==> eitherOf a b
306324 , "curry" -:: (tupleOf [a,b] ==> c) ==> a ==> b ==> c
307325 , "uncurry" -:: (a ==> b ==> c) ==> tupleOf [a,b] ==> c
308326 ] ++ map tuple [0..8]
@@ -347,10 +365,17 @@ maybeFuncs = prefix "Maybe"
347365 [ "maybe" -:: b ==> (a ==> b) ==> maybeOf a ==> b
348366 , "isJust" -:: maybeOf a ==> bool
349367 , "isNothing" -:: maybeOf a ==> bool
350− , "fromMaybe" -:: a ==> maybeOf a ==> a
351− , "consMaybe" -:: maybeOf a ==> listOf a ==> listOf a
352− , "catMaybes" -:: listOf (maybeOf a) ==> listOf a
353− , "catMaybes" -:: (a ==> maybeOf b) ==> listOf a ==> listOf b
368+ , "cons" -:: maybeOf a ==> listOf a ==> listOf a
369+ , "justs" -:: listOf (maybeOf a) ==> listOf a
370+ ]
371+
372+eithers = prefix "Either"
373+ [ "isLeft" -:: eitherOf a b ==> bool
374+ , "isRight" -:: eitherOf a b ==> bool
375+ , "either" -:: (a ==> c) ==> (b ==> c) ==> eitherOf a b ==> c
376+ , "lefts" -:: listOf (eitherOf a b) ==> listOf a
377+ , "rights" -:: listOf (eitherOf a b) ==> listOf b
378+ , "partition" -:: listOf (eitherOf a b) ==> tupleOf [listOf a,listOf b]
354379 ]
355380
356381dictionary =
@@ -410,9 +435,9 @@ automaton =
410435
411436-------- Everything --------
412437
413−hints = mapM (\(n,s) -> (,) n `liftM` rescheme s) hs
414− where hs = concat [ funcs, lists, signals, math, bools, textAttrs
415− , graphicsElement, graphicsColor
416− , concreteSignals, javascript, json, maybeFuncs
417− , http, dictionary, sets, automaton, times, dates
418− ]
438+hints = mapM (\(n,s) -> (,) n `liftM` rescheme s) (concat hs)
439+ where hs = [ funcs, lists, signals, math, bools, textAttrs
440+ , graphicsElement, graphicsColor, eithers, keyboards, touches
441+ , concreteSignals, javascript, json, maybeFuncs
442+ , http, dictionary, sets, automaton, times, dates
443+ ]
elm/src/Types/Types.hs+4
@@ -28,6 +28,9 @@ recordT :: [(String,Type)] -> Map.Map String [Type]
2828recordT fields =
2929 foldl (\r (x,t) -> Map.insertWith (++) x [t] r) Map.empty fields
3030
31+recordOf :: [(String,Type)] -> Type
32+recordOf fields = RecordT (recordT fields) EmptyRecord
33+
3134tipe t = ADT t []
3235
3336int = tipe "Int"
@@ -58,6 +61,7 @@ listOf t = ADT "List" [t]
5861signalOf t = ADT "Signal" [t]
5962tupleOf ts = ADT ("Tuple" ++ show (length ts)) ts
6063maybeOf t = ADT "Maybe" [t]
64+eitherOf a b = ADT "Maybe" [a,b]
6165pairOf t = tupleOf [t,t]
6266point = pairOf int
6367appendable t = Super (Set.fromList [ string, text, listOf t ])