Permalink
Browse files

Added Eq and Ord instances for Tuple.

  • Loading branch information...
1 parent 30fc0ee commit 8ff1d75ee5a07d37645025bc47753110b3cdd7f1 @tomlokhorst committed Jan 22, 2010
Showing with 9 additions and 0 deletions.
  1. +9 −0 src/Generic/Data/Tuple.hs
@@ -1,11 +1,20 @@
module Generic.Data.Tuple where
import Prelude ()
+import Generic.Data.Bool
+import Generic.Data.Eq
+import Generic.Data.Ord
class TupleC j where
mkTuple :: j a -> j b -> j (a, b)
tuple :: (j a -> j b -> j r) -> j (a, b) -> j r
+instance (BoolC j, TupleC j, Eq j a, Eq j b) => Eq j (a, b) where
+ x == y = tuple (\xa xb -> tuple (\ya yb -> xa == ya && xb == yb) y) x
+
+instance (BoolC j, TupleC j, Eq j a, Eq j b, Ord j a, Ord j b) => Ord j (a, b) where
+ x <= y = tuple (\xa xb -> tuple (\ya yb -> xa <= ya && xb <= yb) y) x
+
swap :: TupleC j => j (a, b) -> j (b, a)
swap = tuple (\a b -> mkTuple b a)

0 comments on commit 8ff1d75

Please sign in to comment.