328614fdb33c0093c6550b463a71c84e96bb367c
[ghc-hetmet.git] / ghc / tests / typecheck / should_run / tcrun009.hs
1 {-# OPTIONS -fglasgow-exts #-}
2
3 -- !!! Functional dependencies
4
5 module Main where
6
7 class Foo a b | a -> b where
8     foo :: a -> b
9
10 instance Foo [a] (Maybe a) where
11     foo []    = Nothing
12     foo (x:_) = Just x
13
14 instance Foo (Maybe a) [a] where
15     foo Nothing  = []
16     foo (Just x) = [x]
17
18 test3:: [a] -> [b]
19 test3 = foo . foo
20 -- First foo must use the first instance,
21 -- second must use the second.  So we should
22 -- get in effect:       test3 (x:xs) = [x]
23
24 main:: IO ()
25 main = print (test3 "foo" :: [Int])