Я пытаюсь представить взвешенные ребра. В конечном итоге я хочу, чтобы OutE был экземпляром Eq и Ord с ограничением, что etype является экземпляром Eq и Ord. Предположим, у меня есть следующий файл как temp.hs:
data (Ord etype)=> OutE vtype etype = OutE {destVertex:: vtype, edgeValue::etype}
applyFunBy accessor ordfun = (\x y -> (ordfun (accessor x) (accessor y)))
instance Eq (OutE vtype etype) where
--(==) :: Ord etype => (OutE vtype etype) -> (OutE vtype etype) -> Bool
--(/=) :: Ord etype => (OutE vtype etype) -> (OutE vtype etype) -> Bool
(==) = applyFunBy edgeValue (==)
(/=) = applyFunBy edgeValue (/=)
когда я загружаю это в ghci, я получаю следующие ошибки:
temp.hs:10:19:
Could not deduce (Ord etype)
from the context (Eq (OutE vtype etype))
arising from a use of `edgeValue' at temp.hs:10:19-27
Possible fix:
add (Ord etype) to the context of the instance declaration
In the first argument of `applyFunBy', namely `edgeValue'
In the expression: applyFunBy edgeValue (==)
In the definition of `==': == = applyFunBy edgeValue (==)
temp.hs:11:19:
Could not deduce (Ord etype)
from the context (Eq (OutE vtype etype))
arising from a use of `edgeValue' at temp.hs:11:19-27
Possible fix:
add (Ord etype) to the context of the instance declaration
In the first argument of `applyFunBy', namely `edgeValue'
In the expression: applyFunBy edgeValue (/=)
In the definition of `/=': /= = applyFunBy edgeValue (/=)
Failed, modules loaded: none.
Если включить строки для сигнатур типов для (==) и (\=), я получаю:
temp.hs:6:1:
Misplaced type signature:
== ::
(Ord etype) => (OutE vtype etype) -> (OutE vtype etype) -> Bool
temp.hs:7:1:
Misplaced type signature:
/= ::
(Ord etype) => (OutE vtype etype) -> (OutE vtype etype) -> Bool