git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update prelude classes
9bda0e4Gary Burgess
prelude/prelude.purs+43−27
@@ -13,8 +13,12 @@ module Prelude
13 , Applicative, pure, liftA1
13 , Applicative, pure, liftA1
14 , Bind, (>>=)
14 , Bind, (>>=)
15 , Monad, return, liftM1, ap
15 , Monad, return, liftM1, ap
16− , Num, (+), (-), (*), (/), (%)
16+ , Semiring, (+), zero, (*), one
17+ , Ring, (-)
18+ -- , (%)
17 , negate
19 , negate
20+ , DivisionRing, (/)
21+ , Num
18 , Eq, (==), (/=), refEq, refIneq
22 , Eq, (==), (/=), refEq, refIneq
19 , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
23 , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
20 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
24 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
@@ -24,28 +28,28 @@ module Prelude
24 , Unit(..), unit
28 , Unit(..), unit
25 ) where
29 ) where
26
30
27− -- | An alias for `true`, which can be useful in guard clauses:
31+ -- | An alias for `true`, which can be useful in guard clauses:
28− -- |
32+ -- |
29 -- | E.g.
33 -- | E.g.
30− -- |
34+ -- |
31− -- | max x y | x >= y = x
35+ -- | max x y | x >= y = x
32 -- | | otherwise = y
36 -- | | otherwise = y
33 otherwise :: Boolean
37 otherwise :: Boolean
34 otherwise = true
38 otherwise = true
35
39
36− -- | Flips the order of the arguments to a function of two arguments.
40+ -- | Flips the order of the arguments to a function of two arguments.
37 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
41 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
38 flip f b a = f a b
42 flip f b a = f a b
39
43
40− -- | Returns its first argument and ignores its second.
44+ -- | Returns its first argument and ignores its second.
41 const :: forall a b. a -> b -> a
45 const :: forall a b. a -> b -> a
42 const a _ = a
46 const a _ = a
43
47
44 -- | This function returns its first argument, and can be used to assert type equalities.
48 -- | This function returns its first argument, and can be used to assert type equalities.
45− -- | This can be useful when types are otherwise ambiguous.
49+ -- | This can be useful when types are otherwise ambiguous.
46− -- |
50+ -- |
47 -- | E.g.
51 -- | E.g.
48− -- |
52+ -- |
49 -- | main = print $ [] `asTypeOf` [0]
53 -- | main = print $ [] `asTypeOf` [0]
50 -- |
54 -- |
51 -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
55 -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
@@ -200,18 +204,31 @@ module Prelude
200
204
201 infixl 7 *
205 infixl 7 *
202 infixl 7 /
206 infixl 7 /
203− infixl 7 %
207+ -- infixl 7 %
204
208
205 infixl 6 -
209 infixl 6 -
206 infixl 6 +
210 infixl 6 +
207
211
212+ -- | Addition and multiplication
208− class Num a where
213+ class Semiring a where
214+ (+) :: a -> a -> a
215+ zero :: a
209− (+) :: a -> a -> a
216+ (*) :: a -> a -> a
217+ one :: a
218+
219+ -- | Addition, multiplication, and subtraction
220+ class (Semiring a) <= Ring a where
210 (-) :: a -> a -> a
221 (-) :: a -> a -> a
211− (*) :: a -> a -> a
222+
223+ negate :: forall a. (Ring a) => a -> a
224+ negate a = zero - a
225+
226+ -- | Ring with division (possibly non-commutative field)
227+ class (Ring a) <= DivisionRing a where
212 (/) :: a -> a -> a
228 (/) :: a -> a -> a
213− (%) :: a -> a -> a
229+
214− negate :: a -> a
230+ -- | Definitely commutative field
231+ class (DivisionRing a) <= Num a
215
232
216 foreign import numAdd
233 foreign import numAdd
217 """
234 """
@@ -258,20 +275,19 @@ module Prelude
258 }
275 }
259 """ :: Number -> Number -> Number
276 """ :: Number -> Number -> Number
260
277
261− foreign import numNegate
262− """
263− function numNegate(n) {
264− return -n;
265− }
266− """ :: Number -> Number
267−
268− instance numNumber :: Num Number where
278+ instance semiringNumber :: Semiring Number where
269 (+) = numAdd
279 (+) = numAdd
270− (-) = numSub
280+ zero = 0
271 (*) = numMul
281 (*) = numMul
282+ one = 1
283+
284+ instance ringNumber :: Ring Number where
285+ (-) = numSub
286+
287+ instance divisionRingNumber :: DivisionRing Number where
272 (/) = numDiv
288 (/) = numDiv
273− (%) = numMod
289+
274− negate = numNegate
290+ instance numNumber :: Num Number
275
291
276 newtype Unit = Unit {}
292 newtype Unit = Unit {}
277
293