After much experimentation and brow furrowing, I must beg for help.
I am attempting to define a class that has parameter a, and then
specialize it to a pair, as in the following example:
data Weirder a b = Weirdest a b
class Weird c where
f1 :: c -> c
f2 :: Weirder a b -> c -> Weirder a b
f3 :: Weirder a c -> Weirder c a
f4 :: c -> c -> Bool
instance Weird (d,e) where
f1 (x,y) = (x,y)
f2 w (x,y) = Weirdest x y
f3 (Weirdest x y) = Weirdest y x
f4 (x,y) z = True
The complaint is:
ERROR "x.hs" (line 11): Declared type too general
*** Expression : f2
*** Declared type : Weirder a b -> (c,d) -> Weirder a b
*** Inferred type : Weirder a b -> (a,b) -> Weirder a b
It is complaining that in the class, the type of the second
parameter to function f2 has a simple type "(c,d)", which is unrelated
to the type of the arguments to the constructor Weirdest, namely a and b.
In the instance, the type of the second argument to f2 must be the same
types as the arguments to the constructor Weirdest. But this is exactly what
I want, I want the function in the instance to be valid over a more specific
type than in the class. This seems to have worked for f1, f3 and f4, but
not for f2. What am I missing here? Is there a way to define this?
Thanks in advance
Peter White, Motorola.