I'm writing a comparator to pass to sortBy
but I can't get the type declaration right. The input is two Data.Vector
's, each containing two numbers.
-- Comparator to sort a list of individuals by increasing order of fit-0
-- and for individuals with equal fit-0, with increasing order of fit-1
indCmp :: (Ord a, Num a, Vector a) => a -> a -> Ordering
indCmp x y
| (x ! 0) < (y ! 0) = LT
| (x ! 0) > (y ! 0) = GT
| (x ! 1) < (y ! 1) = LT -- Can assume (x ! 0) == (y ! 0) here and beneath
| (x ! 1) > (y ! 1) = GT
| (x ! 1) == (y ! 1) = EQ
GHCI complains:
Expected a constraint, but 'Vector a' has kind '*'
Vector
is a data type, not a class, so your function type should beWhen I changed this, it compiled for me.