我有以下定義哈斯克爾曖昧類型的錯誤
{-# LANGUAGE MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances,
FlexibleContexts #-}
import qualified Data.Map as M
class Graph g n e | g -> n e where
empty :: g -- returns an empty graph
type Matrix a = [[a]]
data MxGraph a b = MxGraph { nodeMap :: M.Map a Int, edgeMatrix :: Matrix (Maybe b) } deriving Show
instance (Ord n) => Graph (MxGraph n e) n e where
empty = MxGraph M.empty [[]]
當我打電話的空,我得到一個模棱兩可的錯誤類型
*Main> empty
Ambiguous type variables `g0', `n0', `e0' in the constraint: ...
爲什麼會出現這個錯誤?我該如何解決它?
...和你的問題是什麼? – melpomene
向我們顯示包含「空」的代碼,併爲您提供類型錯誤。如果你自己輸入'empty'到ghci中,你必須給它一個類型註釋,例如'empty :: MxGraph Int Int'。 – dave4420
我只是說空着,編輯我的問題 –