我在 Haskell 文件中有这些函数,它们工作正常:
func1 :: Integer -> (Integer,Integer) -> [[String]] -> ([Char],[Char],[Char],[Char]) -> (Integer,Integer)
func1 distance agent mymap moves = func5 (func3 agent (func2 distance agent mymap) moves)
func2 :: Integer -> (Integer,Integer) -> [[String]] -> [(Integer,Integer)]
func3 :: (Ord a, Ord b) => (b,a) -> [(b,a)] -> ([Char],[Char],[Char],[Char]) -> [(b,a)]
func4 :: (Int,Int) -> (Int,Int) -> ([Char],[Char],[Char],a) -> ([Char],[Char],[Char],[Char]) -> [[[Char]]] -> [[[Char]]]
func5 [(a,b)] = (a,b)
但是当我写这个函数时:
func6 agent distance mymap moves moves2 = func4 agent (func1 distance agent mymap moves) moves moves2 mymap
我收到此错误:
*ERROR "play.hs":176 - Type error in application
* * * Expression : moveWithFood agent (giveNearestCorrect distance agent mymap moves) moves moves2 mymap
* * * Term : giveNearestCorrect distance agent mymap moves
* * * Type : (Integer,Integer)
* * * Does not match : (Int,Int)*
与 ghci 相同的错误:
play.hs:176:93:
Couldn't match expected type `Integer' against inferred type `Int'
Expected type: (Integer, Integer)
Inferred type: (Int, Int)
In the second argument of `giveNearestCorrect', namely `agent'
In the second argument of `moveWithFood', namely
`(giveNearestCorrect distance agent mymap moves)'
Failed, modules loaded: none.*
我尝试了几件事来解决它,但我无法成功。你能告诉我我应该怎么做吗?谢谢。