1

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 '*'

tsorn
  • 3,365
  • 1
  • 29
  • 48
  • I suspect this is a duplicate of [this one](http://stackoverflow.com/questions/12018959/string-is-applied-to-too-many-type-arguments/12018975), but with `Vector a` instead of `String`. Does the solution there work for you as well? – Daniel Wagner May 07 '16 at 01:06

1 Answers1

3

Vector is a data type, not a class, so your function type should be

indCmp :: (Ord a, Num a)  => Vector a -> Vector a -> Ordering

When I changed this, it compiled for me.

jamshidh
  • 12,002
  • 17
  • 31