summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/HasKey.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/typecheck/should_compile/HasKey.hs')
-rw-r--r--testsuite/tests/typecheck/should_compile/HasKey.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/HasKey.hs b/testsuite/tests/typecheck/should_compile/HasKey.hs
new file mode 100644
index 0000000000..8da7ee7205
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/HasKey.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FunctionalDependencies #-}
+{-# LANGUAGE UndecidableInstances #-}
+
+-- Provided by Christian Maeder; broke
+-- a pre-release GHC 7.0
+
+module HasKey where
+
+class Ord key => HasKey x key | x -> key where
+ toKey :: x -> key
+
+newtype Keyed x = Keyed { unKey :: x }
+
+lift :: (HasKey x1 key1,HasKey x2 key2)
+ => (key1 -> key2 -> a) -> (Keyed x1 -> Keyed x2 -> a)
+lift f x1 x2 = f (toKey . unKey $ x1) (toKey . unKey $ x2)
+
+instance HasKey x key => Eq (Keyed x) where
+ (==) = lift (==)
+
+instance HasKey x key => Ord (Keyed x)