[project @ 1999-02-09 10:12:24 by sof]
[ghc-hetmet.git] / ghc / tests / typecheck / should_run / tcrun003.hs
1 -- !!! One method class from Sergey Mechveliani 
2 --     showed up problematic newtype dict rep.
3 module Main where
4 import Ratio 
5
6 class MBConvertible a b  where  cm :: a -> b -> Maybe b
7
8 c :: MBConvertible a b => a -> b -> b
9 c                         a    b =  case  cm a b  
10                                     of 
11                                       Just b' -> b'
12                                       _       -> error "c a b  failed"
13
14
15 instance MBConvertible Int Int  where  cm a _ = Just a
16
17 instance (MBConvertible a b,Integral b) => MBConvertible a (Ratio b)
18   where
19   cm a f =  case  cm a (numerator f)  of  Just a' -> Just (a'%1)
20                                           _       -> Nothing 
21   
22 main =  let  f  = 1%1 :: Ratio Int
23              n2 = 2::Int
24              g  = (c n2 f) + f
25         in
26              putStr (shows g "\n")