Skip to content

Commit c4c6789

Browse files
committed
Remove Ord from Bounded
1 parent 829d682 commit c4c6789

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

docs/Prelude.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ instance numUnit :: Num Unit
1717
instance eqUnit :: Eq Unit
1818
instance ordUnit :: Ord Unit
1919
instance boundedUnit :: Bounded Unit
20+
instance boundedOrdUnit :: BoundedOrd Unit
2021
instance booleanAlgebraUnit :: BooleanAlgebra Unit
2122
instance showUnit :: Show Unit
2223
```
@@ -713,6 +714,7 @@ instance semigroupOrdering :: Semigroup Ordering
713714
instance eqOrdering :: Eq Ordering
714715
instance ordOrdering :: Ord Ordering
715716
instance boundedOrdering :: Bounded Ordering
717+
instance boundedOrdOrdering :: BoundedOrd Ordering
716718
instance showOrdering :: Show Ordering
717719
```
718720

@@ -785,7 +787,7 @@ Test whether one value is _non-strictly greater than_ another.
785787
#### `Bounded`
786788

787789
``` purescript
788-
class (Ord a) <= Bounded a where
790+
class Bounded a where
789791
top :: a
790792
bottom :: a
791793
```
@@ -796,14 +798,18 @@ instance boundedBoolean :: Bounded Boolean
796798
instance boundedUnit :: Bounded Unit
797799
instance boundedOrdering :: Bounded Ordering
798800
instance boundedInt :: Bounded Int
801+
instance boundedFn :: (Bounded b) => Bounded (a -> b)
799802
```
800803

801-
The `Bounded` type class represents types that are finite partially
802-
ordered sets.
804+
The `Bounded` type class represents types that are finite.
803805

804-
Instances should satisfy the following law in addition to the `Ord` laws:
806+
Although there are no "internal" laws for `Bounded`, every value of `a`
807+
should be considered less than or equal to `top` by some means, and greater
808+
than or equal to `bottom`.
805809

806-
- Ordering: `bottom <= a <= top`
810+
The lack of explicit `Ord` constraint allows flexibility in the use of
811+
`Bounded` so it can apply to total and partially ordered sets, boolean
812+
algebras, etc.
807813

808814
#### `BooleanAlgebra`
809815

@@ -818,6 +824,7 @@ class (Bounded a) <= BooleanAlgebra a where
818824
``` purescript
819825
instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
820826
instance booleanAlgebraUnit :: BooleanAlgebra Unit
827+
instance booleanAlgebraFn :: (BooleanAlgebra b) => BooleanAlgebra (a -> b)
821828
```
822829

823830
The `BooleanAlgebra` type class represents types that behave like boolean

src/Prelude.purs

+29-5
Original file line numberDiff line numberDiff line change
@@ -699,13 +699,16 @@ unsafeCompare = unsafeCompareImpl LT EQ GT
699699

700700
foreign import unsafeCompareImpl :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
701701

702-
-- | The `Bounded` type class represents types that are finite partially
703-
-- | ordered sets.
702+
-- | The `Bounded` type class represents types that are finite.
704703
-- |
705-
-- | Instances should satisfy the following law in addition to the `Ord` laws:
704+
-- | Although there are no "internal" laws for `Bounded`, every value of `a`
705+
-- | should be considered less than or equal to `top` by some means, and greater
706+
-- | than or equal to `bottom`.
706707
-- |
707-
-- | - Ordering: `bottom <= a <= top`
708-
class (Ord a) <= Bounded a where
708+
-- | The lack of explicit `Ord` constraint allows flexibility in the use of
709+
-- | `Bounded` so it can apply to total and partially ordered sets, boolean
710+
-- | algebras, etc.
711+
class Bounded a where
709712
top :: a
710713
bottom :: a
711714

@@ -725,6 +728,22 @@ instance boundedInt :: Bounded Int where
725728
top = 2147483647
726729
bottom = -2147483648
727730

731+
instance boundedFn :: (Bounded b) => Bounded (a -> b) where
732+
top _ = top
733+
bottom _ = bottom
734+
735+
-- | The `BoundedOrd` type class represents totally ordered finite data types.
736+
-- |
737+
-- | Instances should satisfy the following law in addition to the `Ord` laws:
738+
-- |
739+
-- | - Ordering: `bottom <= a <= top`
740+
class (Bounded a, Ord a) <= BoundedOrd a
741+
742+
instance boundedOrdBoolean :: BoundedOrd Boolean where
743+
instance boundedOrdUnit :: BoundedOrd Unit where
744+
instance boundedOrdOrdering :: BoundedOrd Ordering where
745+
instance boundedOrdInt :: BoundedOrd Int where
746+
728747
-- | The `BooleanAlgebra` type class represents types that behave like boolean
729748
-- | values.
730749
-- |
@@ -769,6 +788,11 @@ instance booleanAlgebraUnit :: BooleanAlgebra Unit where
769788
disj _ _ = unit
770789
not _ = unit
771790

791+
instance booleanAlgebraFn :: (BooleanAlgebra b) => BooleanAlgebra (a -> b) where
792+
conj fx fy a = fx a `conj` fy a
793+
disj fx fy a = fx a `disj` fy a
794+
not fx a = not (fx a)
795+
772796
infixr 2 ||
773797
infixr 3 &&
774798

0 commit comments

Comments
 (0)