Modify a couple of error messages slightly
[ghc.git] / testsuite / tests / gadt / gadt16.hs
1 {-# LANGUAGE GADTs #-}
2
3 {- This code, courtesy of Markus Lauer (markus.lauer-2006@lauerit.de)
4 was rejected by the sophisticated wobbly-type impl in 6.4.1, and
5 with a terrible error message:
6 Sample.hs:22:40:
7 Couldn't match `MayFail' against `MayFail'
8 Expected type: Result s b
9 Inferred type: Result MayFail a
10 In the first argument of `Return', namely `Fail'
11 In a case alternative: Fail -> return Fail
12
13 Strangely it is accepted by the simplified impl in GHC 6.5. -}
14
15 module Sample where
16
17 import Control.Applicative (Applicative(..))
18 import Control.Monad (liftM, ap)
19
20 data Safe
21 data MayFail
22
23 data Result s a where
24 Ok :: a -> Result s a
25 Fail :: Result MayFail a
26
27 newtype M s a = M { unM :: IO (Result s a) }
28
29 instance Functor (M s) where
30 fmap = liftM
31
32 instance Applicative (M s) where
33 pure = return
34 (<*>) = ap
35
36 instance Monad (M s) where
37
38 return x = M (return (Ok x))
39
40 {- this one gives a type error in 6.4.1 -}
41 M m >>= k = M (do res <- m
42 case res of
43 Ok x -> unM (k x)
44 Fail -> return Fail
45 )
46
47 {- while this one works -}
48 -- M m >>= k = M (f m (unM . k))
49 -- where
50 -- f :: IO (Result s a) -> (a -> IO (Result s b)) -> IO (Result s b)
51 -- f m k = do res <- m
52 -- case res of
53 -- Ok x -> k x
54 -- Fail -> return Fail
55
56
57