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 spec for Ord #233

Closed
gabejohnson opened this issue Mar 24, 2017 · 4 comments
Closed

Add spec for Ord #233

gabejohnson opened this issue Mar 24, 2017 · 4 comments

Comments

@gabejohnson
Copy link
Member

gabejohnson commented Mar 24, 2017

Motivated by sanctuary-js/sanctuary#353 I think it makes sense to add Ord.

From purescript-prelude

-- | The `Ord` type class represents types which support comparisons with a
-- | _total order_.
-- |
-- | `Ord` instances should satisfy the laws of total orderings:
-- |
-- | - Reflexivity: `a <= a`
-- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
-- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
class Eq a <= Ord a where
  compare :: a -> a -> Ordering

This may require specifying Ordering as well (though I haven't seen much movement on spec'ing data types #185):

From purescript-prelude

-- | The `Ordering` data type represents the three possible outcomes of
-- | comparing two values:
-- |
-- | `LT` - The first value is _less than_ the second.
-- | `GT` - The first value is _greater than_ the second.
-- | `EQ` - The first value is _equal to_ the second.
data Ordering = LT | GT | EQ

Specifying Ord would allow generalizing several comparison (lt and friends, min & max) as well as sorting functions (sort, sortBy).

@davidchambers
Copy link
Member

To avoid specifying Ordering we could use Number (though I'd prefer to limit the values to -1, 0, and 1).

@gabejohnson
Copy link
Member Author

@davidchambers that would allow us to state the laws without referencing functions not defined in the spec. Though, by limiting the allowable values of Number you are still specifying. You're just not giving a name to the specification.

@gabejohnson
Copy link
Member Author

We could just punt by adding a pointer to the 262 spec.

@gcanti
Copy link

gcanti commented Mar 29, 2017

FYI in fp-ts I'm using Ordering and Ord borrowed from PureScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants