
Forgot to reply to the list, sorry.
---------- Forwarded message ----------
From: Tobias Brandt
data Foo a = Foo a
class TwoPi a where div2pi :: (Floating b) => a -> b
div2pi is polymorphic in a AND b. They are completely independent.
instance (Floating a) => TwoPi (Foo a) where div2pi (Foo a) = a / (2*pi)
but here, div2pi has type Floating a => Foo a -> a.
data Foo a = Foo a
class TwoPi a where div2pi :: a -> Float
instance (Floating b) => TwoPi (Foo b) where div2pi (Foo b) = b / (2*pi)
now div2pi has type Floating a :: Foo a -> a, but should have Floating a :: Foo a -> Float There are two possible solutions (I can think of). 1. make div2pi less polymorphic: class TwoPi a where div2pi :: a -> a then your first instance works 2. use associated types: class TwoPi a where type TwoPiRes a div2pi :: a -> TwoPiRes a instance Floating a => TwoPi (Foo a) where type TwoPiRes (Foo a) = a div2pi (Foo a) = a /(2*pi)