[Haskell] type inference & instance extensions
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Mon Jan 19 08:53:31 EST 2009
Doug McIlroy <doug at cs.dartmouth.edu> wrote:
> instance Num a => Num (a,a) where
> (x,y) * (u,v) = (x*u-y*v, x*v+y*u)
>
> Unfortunately, type inference isn't strong enough to cope with
>
> (1,1)*(1,1)
I'm guessing it is because
(fromInteger 1, fromInteger 1) :: (Num a, Num b) => (a,b)
So you want to force the two components to be the same type:
let x = 1 in (x,x)*(x,x)
Or for differing component values:
let x = 1 in (x,2`asTypeOf`x)*(3`asTypeOf`x,4`asTypeOf`x)
Regards,
Malcolm
More information about the Haskell
mailing list