From 8ecc43dd80996ce3b9f1c67bb8276218770269b0 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Thu, 13 Aug 2015 13:53:56 +0100 Subject: [PATCH] Add Bounded Char instance --- docs/Prelude.md | 13 ++++++++----- src/Prelude.js | 9 ++++++--- src/Prelude.purs | 9 +++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/Prelude.md b/docs/Prelude.md index 679f28eb..df56019c 100644 --- a/docs/Prelude.md +++ b/docs/Prelude.md @@ -836,6 +836,12 @@ _left-associative / precedence 4_ Test whether one value is _non-strictly greater than_ another. +#### `unsafeCompare` + +``` purescript +unsafeCompare :: forall a. a -> a -> Ordering +``` + #### `Bounded` ``` purescript @@ -860,6 +866,7 @@ instance boundedBoolean :: Bounded Boolean instance boundedUnit :: Bounded Unit instance boundedOrdering :: Bounded Ordering instance boundedInt :: Bounded Int +instance boundedChar :: Bounded Char instance boundedFn :: (Bounded b) => Bounded (a -> b) ``` @@ -881,6 +888,7 @@ instance boundedOrdBoolean :: BoundedOrd Boolean instance boundedOrdUnit :: BoundedOrd Unit instance boundedOrdOrdering :: BoundedOrd Ordering instance boundedOrdInt :: BoundedOrd Int +instance boundedOrdChar :: BoundedOrd Char ``` #### `BooleanAlgebra` @@ -975,9 +983,4 @@ instance showArray :: (Show a) => Show (Array a) instance showOrdering :: Show Ordering ``` -#### `unsafeCompare` -``` purescript -unsafeCompare :: forall a. a -> a -> Ordering -``` -The `unsafeCompare` function is mainly intended for module writers supporting native types via the FFI, and not for general comparisons. diff --git a/src/Prelude.js b/src/Prelude.js index 6e4d364a..e0b161ce 100644 --- a/src/Prelude.js +++ b/src/Prelude.js @@ -172,7 +172,12 @@ exports.unsafeCompareImpl = function (lt) { }; }; -//- Lattice -------------------------------------------------------------------- +//- Bounded -------------------------------------------------------------------- + +exports.topChar = String.fromCharCode(65535); +exports.bottomChar = String.fromCharCode(0); + +//- BooleanAlgebra ------------------------------------------------------------- exports.boolOr = function (b1) { return function (b2) { @@ -186,8 +191,6 @@ exports.boolAnd = function (b1) { }; }; -//- ComplementedLattice -------------------------------------------------------- - exports.boolNot = function (b) { return !b; }; diff --git a/src/Prelude.purs b/src/Prelude.purs index f7458b17..05e892ac 100644 --- a/src/Prelude.purs +++ b/src/Prelude.purs @@ -737,10 +737,18 @@ instance boundedInt :: Bounded Int where top = 2147483647 bottom = -2147483648 +-- | Characters fall within the Unicode range. +instance boundedChar :: Bounded Char where + top = topChar + bottom = bottomChar + instance boundedFn :: (Bounded b) => Bounded (a -> b) where top _ = top bottom _ = bottom +foreign import topChar :: Char +foreign import bottomChar :: Char + -- | The `BoundedOrd` type class represents totally ordered finite data types. -- | -- | Instances should satisfy the following law in addition to the `Ord` laws: @@ -752,6 +760,7 @@ instance boundedOrdBoolean :: BoundedOrd Boolean where instance boundedOrdUnit :: BoundedOrd Unit where instance boundedOrdOrdering :: BoundedOrd Ordering where instance boundedOrdInt :: BoundedOrd Int where +instance boundedOrdChar :: BoundedOrd Char where -- | The `BooleanAlgebra` type class represents types that behave like boolean -- | values.