Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bounded Char instance #37

Merged
merged 1 commit into from
Aug 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/Prelude.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
```

Expand All @@ -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`
Expand Down Expand Up @@ -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.
9 changes: 6 additions & 3 deletions src/Prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -186,8 +191,6 @@ exports.boolAnd = function (b1) {
};
};

//- ComplementedLattice --------------------------------------------------------

exports.boolNot = function (b) {
return !b;
};
Expand Down
9 changes: 9 additions & 0 deletions src/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down