Skip to content

Commit df955e0

Browse files
committed
Merge pull request #39 from purescript/revert-38-revert-37-bounded-char-instance
Revert "Revert "Add Bounded Char instance""
2 parents b74b07d + 2093adb commit df955e0

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

docs/Prelude.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,12 @@ _left-associative / precedence 4_
836836

837837
Test whether one value is _non-strictly greater than_ another.
838838

839+
#### `unsafeCompare`
840+
841+
``` purescript
842+
unsafeCompare :: forall a. a -> a -> Ordering
843+
```
844+
839845
#### `Bounded`
840846

841847
``` purescript
@@ -860,6 +866,7 @@ instance boundedBoolean :: Bounded Boolean
860866
instance boundedUnit :: Bounded Unit
861867
instance boundedOrdering :: Bounded Ordering
862868
instance boundedInt :: Bounded Int
869+
instance boundedChar :: Bounded Char
863870
instance boundedFn :: (Bounded b) => Bounded (a -> b)
864871
```
865872

@@ -881,6 +888,7 @@ instance boundedOrdBoolean :: BoundedOrd Boolean
881888
instance boundedOrdUnit :: BoundedOrd Unit
882889
instance boundedOrdOrdering :: BoundedOrd Ordering
883890
instance boundedOrdInt :: BoundedOrd Int
891+
instance boundedOrdChar :: BoundedOrd Char
884892
```
885893

886894
#### `BooleanAlgebra`
@@ -975,9 +983,4 @@ instance showArray :: (Show a) => Show (Array a)
975983
instance showOrdering :: Show Ordering
976984
```
977985

978-
#### `unsafeCompare`
979986

980-
``` purescript
981-
unsafeCompare :: forall a. a -> a -> Ordering
982-
```
983-
The `unsafeCompare` function is mainly intended for module writers supporting native types via the FFI, and not for general comparisons.

src/Prelude.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ exports.unsafeCompareImpl = function (lt) {
172172
};
173173
};
174174

175-
//- Lattice --------------------------------------------------------------------
175+
//- Bounded --------------------------------------------------------------------
176+
177+
exports.topChar = String.fromCharCode(65535);
178+
exports.bottomChar = String.fromCharCode(0);
179+
180+
//- BooleanAlgebra -------------------------------------------------------------
176181

177182
exports.boolOr = function (b1) {
178183
return function (b2) {
@@ -186,8 +191,6 @@ exports.boolAnd = function (b1) {
186191
};
187192
};
188193

189-
//- ComplementedLattice --------------------------------------------------------
190-
191194
exports.boolNot = function (b) {
192195
return !b;
193196
};

src/Prelude.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,18 @@ instance boundedInt :: Bounded Int where
737737
top = 2147483647
738738
bottom = -2147483648
739739

740+
-- | Characters fall within the Unicode range.
741+
instance boundedChar :: Bounded Char where
742+
top = topChar
743+
bottom = bottomChar
744+
740745
instance boundedFn :: (Bounded b) => Bounded (a -> b) where
741746
top _ = top
742747
bottom _ = bottom
743748

749+
foreign import topChar :: Char
750+
foreign import bottomChar :: Char
751+
744752
-- | The `BoundedOrd` type class represents totally ordered finite data types.
745753
-- |
746754
-- | Instances should satisfy the following law in addition to the `Ord` laws:
@@ -752,6 +760,7 @@ instance boundedOrdBoolean :: BoundedOrd Boolean where
752760
instance boundedOrdUnit :: BoundedOrd Unit where
753761
instance boundedOrdOrdering :: BoundedOrd Ordering where
754762
instance boundedOrdInt :: BoundedOrd Int where
763+
instance boundedOrdChar :: BoundedOrd Char where
755764

756765
-- | The `BooleanAlgebra` type class represents types that behave like boolean
757766
-- | values.

0 commit comments

Comments
 (0)