on master help sign in
Add Comparable super-type, along with `compare` function.
commitb5c941349f2765b5b8d82e35493969a0e6254d42 authorevancz <info@elm-lang.org> dateSat 28 Jul 2012, 20:36 (14 years ago) parentb89d822
2 files changed+8−4
elm/src/Types/Hints.hs+7−4 elm/src/Types/Types.hs+1
elm/src/Types/Hints.hs+7−4
@@ -128,8 +128,9 @@ concreteSignals =
128128-------- Math and Binops --------
129129
130130binop t = t ==> t ==> t
131−numScheme t name = (name, Forall [0] [VarT 0 :<: number] (t (VarT 0)))
132−timeScheme name t = (name, Forall [0] [VarT 0 :<: time] (t (VarT 0)))
131+scheme1 super t name = (name, Forall [0] [VarT 0 :<: super] (t (VarT 0)))
132+numScheme t name = scheme1 number t name
133+timeScheme name t = scheme1 time t name
133134twoNums f name =
134135 (,) name . Forall [0,1] [ VarT 0 :<: number, VarT 1 :<: number ] $
135136 f (VarT 0) (VarT 1)
@@ -148,8 +149,10 @@ math =
148149bools =
149150 [ "not" -: bool ==> bool ] ++
150151 hasType (binop bool) ["&&","||"] ++
151− map (numScheme (\n -> n ==> n ==> bool)) ["<",">","<=",">="]
152−
152+ map (scheme1 comparable (\t -> t ==> t ==> bool)) ["<",">","<=",">="] ++
153+ [ ( "compare"
154+ , Forall [0,1] [ VarT 0 :<: comparable ] (VarT 0 ==> VarT 0 ==> VarT 1) )
155+ ]
153156
154157-------- Polymorphic Functions --------
155158
elm/src/Types/Types.hs+1
@@ -50,6 +50,7 @@ maybeOf t = ADT "Maybe" [t]
5050pairOf t = tupleOf [t,t]
5151point = pairOf int
5252appendable t = SuperType "Appendable" (Set.fromList [ string, text, listOf t ])
53+comparable = SuperType "Comparable" (Set.fromList [ int, float, char, string, tipe "Number", tipe "Time" ])
5354
5455jsBool = tipe "JSBool"
5556jsNumber = tipe "JSNumber"