summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/FD2.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/typecheck/should_compile/FD2.hs')
-rw-r--r--testsuite/tests/typecheck/should_compile/FD2.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/FD2.hs b/testsuite/tests/typecheck/should_compile/FD2.hs
new file mode 100644
index 0000000000..b4623a8743
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/FD2.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
+{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
+
+-- Trac #1783
+-- Like Trac #1781 you could argue that this one should succeed
+-- but we stick with the old behaviour for now. When we do
+-- fundeps properly it'll probably start to work
+
+module ShouldCompile where
+
+import Prelude hiding (foldr, foldr1)
+
+import Data.Maybe
+
+class Elem a e | a -> e
+
+class Foldable a where
+ foldr :: Elem a e => (e -> b -> b) -> b -> a -> b
+
+-- foldr1 :: forall e. Elem a e => (e -> e -> e) -> a -> e -- WORKS!
+ foldr1 :: Elem a e => (e -> e -> e) -> a -> e
+ foldr1 f xs = fromMaybe (error "foldr1: empty structure")
+ (foldr mf Nothing xs)
+ where mf :: Elem a e => (e -> Maybe e -> Maybe e)
+ mf x Nothing = Just x
+ mf x (Just y) = Just (f x y)