我有這樣的功能:哈斯克爾的數據類型錯誤
data Memory = Memory
{visited::[Point]
,dfsstack::[Point]
,currentPoz::Point
}deriving(Eq)
perceiveAndAct :: SVal -> [Cardinal] -> a -> (Action, a)
perceiveAndAct s cs m
| elem W cs == True && elem N cs == True && elem E cs == True && elem S cs == False = (Just S, Memory (visited m) (dfsstack m) (currentPoz m))
把米,而不是Memory (visited m) (dfsstack m) (currentPoz m)
工作正常,否則,它給了我:
Couldn't match expected type `(a, b)'
against inferred type `Memory -> Point'
In the first argument of `fst', namely `currentPoz'
In the first argument of `($)', namely `fst currentPoz'
In the expression: fst currentPoz $ currentPoz m
可能是什麼問題呢?
錯誤信息所指的'fst currentPoz $ currentPoz m'在哪裏? – hammar 2012-04-14 18:52:16
順便說一句,無論你有什麼'blah == True',你都可以簡化爲'blah'(例如,簡化'elem W cs == True'到'elem W cs')。同樣,您可以將'elem S cs == False'簡化爲'notElem S cs'。 – dave4420 2012-04-14 20:26:18