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

MR K P SCHUPKE k.schupke at imperial.ac.uk
Mon Mar 29 17:19:18 EST 2004


>Could not deduce (Num a) from the context (VectorSpace VList)

The problem is in the definition: 

zero                      = VList (repeat 0)

Is "0" an Int or an Integer? 

To define zero, instances need to be parameterised by 
vector type:

EG:

class VectorSpace v a where
   zero  :: v a
   add   :: v a -> v a -> v a
   scale :: a -> v a -> v a

instance VectorSpace VList Int where
   zero                      = VList (repeat 0)
...

instance VectorSpace VList Float where
   zero                      = VList (repeat 0.0)

etc...


>Could not deduce (Num a) from the context (VectorSpace VList)

The problem is in the definition: 

zero                      = VList (repeat 0)

Is "0" an Int or an Integer? 

To define zero, instances need to be parameterised by 
vector type:

EG:

class VectorSpace v a where
   zero  :: v a
   add   :: v a -> v a -> v a
   scale :: a -> v a -> v a

instance VectorSpace VList Int where
   zero                      = VList (repeat 0)
...

instance VectorSpace VList Float where
   zero                      = VList (repeat 0.0)

etc...

	Regards,
	Keean.


More information about the Haskell-Cafe mailing list