on master help sign in
Add Comparable super-type, along with `compare` function.
b5c9413evancz
elm/src/Types/Hints.hs+7−4
@@ -128,8 +128,9 @@ concreteSignals =
128-------- Math and Binops --------
128-------- Math and Binops --------
129
129
130binop t = t ==> t ==> t
130binop t = t ==> t ==> t
131+scheme1 super t name = (name, Forall [0] [VarT 0 :<: super] (t (VarT 0)))
131−numScheme t name = (name, Forall [0] [VarT 0 :<: number] (t (VarT 0)))
132+numScheme t name = scheme1 number t name
132−timeScheme name t = (name, Forall [0] [VarT 0 :<: time] (t (VarT 0)))
133+timeScheme name t = scheme1 time t name
133twoNums f name =
134twoNums f name =
134 (,) name . Forall [0,1] [ VarT 0 :<: number, VarT 1 :<: number ] $
135 (,) name . Forall [0,1] [ VarT 0 :<: number, VarT 1 :<: number ] $
135 f (VarT 0) (VarT 1)
136 f (VarT 0) (VarT 1)
@@ -148,8 +149,10 @@ math =
148bools =
149bools =
149 [ "not" -: bool ==> bool ] ++
150 [ "not" -: bool ==> bool ] ++
150 hasType (binop bool) ["&&","||"] ++
151 hasType (binop bool) ["&&","||"] ++
151− map (numScheme (\n -> n ==> n ==> bool)) ["<",">","<=",">="]
152+ map (scheme1 comparable (\t -> t ==> t ==> bool)) ["<",">","<=",">="] ++
152−
153+ [ ( "compare"
154+ , Forall [0,1] [ VarT 0 :<: comparable ] (VarT 0 ==> VarT 0 ==> VarT 1) )
155+ ]
153
156
154-------- Polymorphic Functions --------
157-------- Polymorphic Functions --------
155
158
elm/src/Types/Types.hs+1
@@ -50,6 +50,7 @@ maybeOf t = ADT "Maybe" [t]
50pairOf t = tupleOf [t,t]
50pairOf t = tupleOf [t,t]
51point = pairOf int
51point = pairOf int
52appendable t = SuperType "Appendable" (Set.fromList [ string, text, listOf t ])
52appendable t = SuperType "Appendable" (Set.fromList [ string, text, listOf t ])
53+comparable = SuperType "Comparable" (Set.fromList [ int, float, char, string, tipe "Number", tipe "Time" ])
53
54
54jsBool = tipe "JSBool"
55jsBool = tipe "JSBool"
55jsNumber = tipe "JSNumber"
56jsNumber = tipe "JSNumber"