tags:

views:

67

answers:

1

Would like to declare

data (Coord a) => Triangle a = Triangle{t0 :: a, t1 :: a, t2 :: a}

However I am getting

Geometry.hs:15:19:Kind mis-match Expected kind * -> *', but p' has kind *' In the class declaration for Coord'

where Coord is defined as

class (Traversable p, Functor p, Foldable p, Applicative p) => Coord p where

getComponents :: Num a => p a -> [a]
getComponents = toList

fromComponents :: Num a => [a] -> p a

magSq :: Num a => p a -> a
magSq = Prelude.sum . map (\x -> x * x) . getComponents

dotProduct :: Num a => p a -> p a -> a
dotProduct a b = Prelude.sum $ zipWith (*) (getComponents a) (getComponents b)

Any ideas?

PS. Code is a slightly modified version of what is found in the Data.SG package

+3  A: 

This might work for you:

data (Coord p, Num a) => Triangle p a = Triangle {t0 :: p a, t1 :: p a, t2 :: p a}

In short, a type that has the typeclass Coord is a parameterized type. You have to supply the parameter.

(The kind of a type tells you whether it has any parameters. Types of kind * can have actual values. All other types are parameterized. Any type that has the typeclass Coord is of kind * -> *, which means it takes one argument of kind *.)

Jason Orendorff
Thanks. I'll give that a shot just to see if it works, but after reading more it seems like it is bad form to put that quantifier in the constructor anyway, because then it requires a similar quantification on all the function signatures, or something like that.
Jonathan Fischoff