[Haskell-cafe] Context for type parameters of type constructors

Henning Thielemann iakd0 at clusterf.urz.uni-halle.de
Tue Mar 30 13:59:40 EST 2004


On Tue, 30 Mar 2004, MR K P SCHUPKE wrote:

> >I didn't get the point yet why the context for 'data'
> >is not sufficient for the 'instance' method definition.
> 
> Not sure who's relpy you're replying to,

This was clearly an answer to Dylan Thurston.

> but I thought my response was pretty clear (I would though)... 

I'm not sure you got the point of my question. :-(

> You could get rid of zero and have:
> 
> class VectorSpace v where
>    set :: Num a => a -> v a
>    add :: Num a => v a -> v a -> v a
>    scale :: Num a => a -> v a -> v a
> 
> Should do the trick! (zero becomes "set 0")

This wouldn't change much because the compiler also complains about the
other instance definitions, e.g.
  instance VectorSpace VList where
    add (VList x) (VList y) = VList (zipWith (+) x y)
 is rejected because the compiler don't believes that the type of x and y
is in class Num. 

My question was why he doesn't believe that. My definition
  data (Num a) => VList a = VList [a]
 clearly states that VLists will ever get types of class Num as
parameters. 




More information about the Haskell-Cafe mailing list