[Haskell-cafe] Trouble with types

Stefan Holdermans sholderm at students.cs.uu.nl
Fri Jul 23 13:36:01 EDT 2004


Kari,

Others have not mentioned the change required in the type signature yet.

< temp :: (Real a) => Object (Energy a) (HeatC a) -> Temp a
< temp Object (Energy e) (HeatC c) = Temp e*c

> temp :: forall a . (Real a) => Object a a -> Temp a
> temp (Object (Energy e) (HeatC c)) =  Temp (e * c) 

HTH,

Stefan

> data (Real a) => Energy a = Energy a deriving (Eq, Ord, Show)
> data (Real a) => HeatC a  = HeatC a  deriving (Eq, Ord, Show)
> data (Real a) => Temp a   = Temp a   deriving (Eq, Ord, Show)

> data Object h c           = Object { energy :: Energy h,
>                                      heatc  :: HeatC c
>                                    } deriving (Eq, Show)

> main =  let obj = Object { energy = Energy 2.5 
>                          , heatc  = HeatC 12.0
>                          }
>         in  print (temp obj) -- prints "Temp 30.0"




More information about the Haskell-Cafe mailing list