Skip to content

Commit 2565615

Browse files
authored
Merge pull request #117 from purescript/eq-ord-1
Add `Eq1` and `Ord1` classes
2 parents 21067a4 + 94ce813 commit 2565615

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Data/Eq.purs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Data.Eq (class Eq, eq, (==), notEq, (/=)) where
1+
module Data.Eq
2+
( class Eq, eq, (==), notEq, (/=)
3+
, class Eq1, eq1, notEq1
4+
) where
25

36
import Data.Unit (Unit)
47
import Data.Void (Void)
@@ -54,3 +57,13 @@ instance eqArray :: Eq a => Eq (Array a) where
5457
foreign import refEq :: forall a. a -> a -> Boolean
5558
foreign import refIneq :: forall a. a -> a -> Boolean
5659
foreign import eqArrayImpl :: forall a. (a -> a -> Boolean) -> Array a -> Array a -> Boolean
60+
61+
-- | The `Eq` type class represents type constructors with decidable equality.
62+
class Eq1 f where
63+
eq1 :: forall a. Eq a => f a -> f a -> Boolean
64+
65+
instance eq1Array :: Eq1 Array where
66+
eq1 = eq
67+
68+
notEq1 :: forall f a. (Eq1 f, Eq a) => f a -> f a -> Boolean
69+
notEq1 x y = (x `eq1` y) == false

src/Data/Ord.purs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Data.Ord
22
( class Ord, compare
3+
, class Ord1, compare1
34
, lessThan, (<)
45
, lessThanOrEq, (<=)
56
, greaterThan, (>)
@@ -13,7 +14,7 @@ module Data.Ord
1314
, module Data.Ordering
1415
) where
1516

16-
import Data.Eq (class Eq)
17+
import Data.Eq (class Eq, class Eq1)
1718
import Data.Function (on)
1819
import Data.Ord.Unsafe (unsafeCompare)
1920
import Data.Ordering (Ordering(..))
@@ -161,3 +162,10 @@ abs x = if x >= zero then x else negate x
161162
-- | any `x`, we should have `signum x * abs x == x`.
162163
signum :: forall a. (Ord a, Ring a) => a -> a
163164
signum x = if x >= zero then one else negate one
165+
166+
-- | The `Ord1` type class represents totally ordered type constructors.
167+
class Eq1 f <= Ord1 f where
168+
compare1 :: forall a. Ord a => f a -> f a -> Ordering
169+
170+
instance ord1Array :: Ord1 Array where
171+
compare1 = compare

0 commit comments

Comments
 (0)