on master help sign in
Instances in builtins
a927d65Edwin Brady
lib/builtins.idr+26−20
@@ -81,22 +81,32 @@ class Num a where {
81 (*) : a -> a -> a;
81 (*) : a -> a -> a;
82}
82}
83
83
84−instance numInt : Num Int;
84+instance Num Int where {
85−instance numInt = instanceNum prim__addInt prim__subInt prim__mulInt;
85+ (+) = prim__addInt;
86+ (-) = prim__subInt;
87+ (*) = prim__mulInt;
88+}
86
89
87−instance numFloat : Num Float;
90+instance Num Float where {
88−instance numFloat = instanceNum prim__addFloat prim__subFloat prim__mulFloat;
91+ (+) = prim__addFloat;
92+ (-) = prim__subFloat;
93+ (*) = prim__mulFloat;
94+}
89
95
90class Eq a where {
96class Eq a where {
91 (==) : a -> a -> Bool;
97 (==) : a -> a -> Bool;
92 (/=) : a -> a -> Bool;
98 (/=) : a -> a -> Bool;
93}
99}
94
100
95−instance EqInt : Eq Int;
101+instance Eq Int where {
96−instance EqInt = instanceEq (boolOp prim__eqInt) (\x, y => not (x == y));
102+ (==) = boolOp prim__eqInt;
103+ (/=) x y = not (x == y);
104+}
97
105
98−instance EqFloat : Eq Float;
106+instance Eq Float where {
99−instance EqFloat = instanceEq (boolOp prim__eqFloat) (\x, y => not (x == y));
107+ (==) = boolOp prim__eqFloat;
108+ (/=) x y = not (x == y);
109+}
100
110
101data Ordering = LT | EQ | GT;
111data Ordering = LT | EQ | GT;
102
112
@@ -104,20 +114,16 @@ class Eq a => Ord a where {
104 compare : a -> a -> Ordering;
114 compare : a -> a -> Ordering;
105}
115}
106
116
107−instance OrdInt : Ord Int;
117+instance Ord Int where {
108−instance OrdInt = instanceOrd cmpInt where {
109− cmpInt : Int -> Int -> Ordering;
110− cmpInt x y = if (x == y) then EQ else
118+ compare x y = if (x == y) then EQ else
111− if (boolOp prim__ltInt x y) then LT else
119+ if (boolOp prim__ltInt x y) then LT else
112− GT;
120+ GT;
113}
121}
114
122
115−instance OrdFloat : Ord Float;
123+instance Ord Float where {
116−instance OrdFloat = instanceOrd cmpFloat where {
117− cmpFloat : Float -> Float -> Ordering;
118− cmpFloat x y = if (x == y) then EQ else
124+ compare x y = if (x == y) then EQ else
119− if (boolOp prim__ltFloat x y) then LT else
125+ if (boolOp prim__ltFloat x y) then LT else
120− GT;
126+ GT;
121}
127}
122
128
123div : Int -> Int -> Int;
129div : Int -> Int -> Int;