2016-05-07 14 views
0

Ich schreibe einen Komparator, um an sortBy übergeben, aber ich kann nicht die Typ-Deklaration richtig. Die Eingabe ist zwei Data.Vector 's, die jeweils zwei Nummern enthalten.Haskell-Vektor-Typ Erklärung

-- 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 klagt:

eine Einschränkung erwartet, aber 'Vector a' hat Art '*'

+0

Ich vermute, das ist ein Duplikat von [diesem] (http://stackoverflow.com/questions/12018959/string-is-applied-to-too-many-type-arguments/12018975), aber mit 'Vector a' statt 'String'. Funktioniert die Lösung auch für Sie? –

Antwort

3

Vector ist ein Datentyp, keine Klasse, so dass Ihr Funktionstyp sollte

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

Wenn ich das änderte, kompilierte es für mich.