diff options
Diffstat (limited to 'testsuite/tests/typecheck/should_run/tcrun009.hs')
-rw-r--r-- | testsuite/tests/typecheck/should_run/tcrun009.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_run/tcrun009.hs b/testsuite/tests/typecheck/should_run/tcrun009.hs new file mode 100644 index 0000000000..1adc350084 --- /dev/null +++ b/testsuite/tests/typecheck/should_run/tcrun009.hs @@ -0,0 +1,25 @@ +{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-} + +-- !!! Functional dependencies + +module Main where + +class Foo a b | a -> b where + foo :: a -> b + +instance Foo [a] (Maybe a) where + foo [] = Nothing + foo (x:_) = Just x + +instance Foo (Maybe a) [a] where + foo Nothing = [] + foo (Just x) = [x] + +test3:: [a] -> [a] +test3 = foo . foo +-- First foo must use the first instance, +-- second must use the second. So we should +-- get in effect: test3 (x:xs) = [x] + +main:: IO () +main = print (test3 "foo") |