Skip to content

Add Eq1 and Ord1 instances #26

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

Merged
merged 1 commit into from
Mar 2, 2017
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
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"package.json"
],
"dependencies": {
"purescript-foldable-traversable": "^2.0.0"
"purescript-foldable-traversable": "^2.0.0",
"purescript-prelude": "^2.4.0"
}
}
6 changes: 6 additions & 0 deletions src/Data/Tuple.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import Control.Lazy (class Lazy, defer)
import Data.Bifoldable (class Bifoldable)
import Data.Bifunctor (class Bifunctor)
import Data.Bitraversable (class Bitraversable)
import Data.Eq (class Eq1)
import Data.Foldable (class Foldable, foldMap)
import Data.Functor.Invariant (class Invariant, imapF)
import Data.HeytingAlgebra (implies, ff, tt)
import Data.Maybe (Maybe(..))
import Data.Maybe.First (First(..))
import Data.Monoid (class Monoid, mempty)
import Data.Newtype (unwrap)
import Data.Ord (class Ord1)
import Data.Traversable (class Traversable)

-- | A simple product type for wrapping a pair of component values.
Expand All @@ -33,12 +35,16 @@ instance showTuple :: (Show a, Show b) => Show (Tuple a b) where
-- | there are `Eq` instances for both component types.
derive instance eqTuple :: (Eq a, Eq b) => Eq (Tuple a b)

instance eq1Tuple :: Eq a => Eq1 (Tuple a) where eq1 = eq

-- | Allows `Tuple`s to be compared with `compare`, `>`, `>=`, `<` and `<=`
-- | whenever there are `Ord` instances for both component types. To obtain
-- | the result, the `fst`s are `compare`d, and if they are `EQ`ual, the
-- | `snd`s are `compare`d.
derive instance ordTuple :: (Ord a, Ord b) => Ord (Tuple a b)

instance ord1Tuple :: Ord a => Ord1 (Tuple a) where compare1 = compare

instance boundedTuple :: (Bounded a, Bounded b) => Bounded (Tuple a b) where
top = Tuple top top
bottom = Tuple bottom bottom
Expand Down