
I'm new to Haskell, as you can probably tell... I have the following data types: data Real a => Energy a = Energy a deriving (Eq, Ord, Show) data Real a => HeatC a = HeatC a deriving (Eq, Ord, Show) data Object h c = Object {energy :: (Energy h), heatc :: (HeatC c)} deriving (Eq, Show) data Real a => Temp a = Temp a deriving (Eq, Ord, Show) I'd like to make a function to calculate the temperature of an object. Physically this is the total heat times the heat capacity. I tried this with the following: temp :: (Real a) => Object (Energy a) (HeatC a) -> Temp a temp Object (Energy e) (HeatC c) = Temp e*c But this fails in hugs with: ERROR "temp.hs":22 - Constructor "Object" must have exactly 2 arguments in pattern What's the syntax to use here? Should I do this in some other way? Should I use newtype here instead of data?

On Fri, Jul 23, 2004 at 07:18:28PM +0300, Kari Pahula wrote:
temp :: (Real a) => Object (Energy a) (HeatC a) -> Temp a temp Object (Energy e) (HeatC c) = Temp e*c
Probably this, but I didn't check: temp (Object (Energy e) (HeatC c)) = Temp e*c Best regards, Tom -- .signature: Too many levels of symbolic links

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"

On 2004-07-23 at 19:18+0300 Kari Pahula wrote:
temp :: (Real a) => Object (Energy a) (HeatC a) -> Temp a temp Object (Energy e) (HeatC c) = Temp e*c
But this fails in hugs with: ERROR "temp.hs":22 - Constructor "Object" must have exactly 2 arguments in pattern
You've given temp three arguments: Object, (Energy e) and (HeatC c). You meant:
temp (Object (Energy e) (HeatC c)) = Temp e*c
HTH -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk
participants (4)
-
Jon Fairbairn
-
Kari Pahula
-
Stefan Holdermans
-
Tomasz Zielonka