【发布时间】:2019-04-16 21:22:55
【问题描述】:
s 和 a 是类型变量。
在构造函数中,前两个参数是数据,然后是它的父级,它在图中的级别,然后是它的子级列表。
data Node s a = Root | Node s a (Node s a) Int [Node s a]
createRoot :: (ProblemState s a) => s-> a -> Node s a
createRoot state act= Node (state act Root 0 [])
我已经将完全相同数量的 5 个参数传递给 Node 构造函数,但是我遇到了错误。
• Couldn't match expected type ‘Node s a’
with actual type ‘a1
-> Node s1 a1 -> Int -> [Node s1 a1] -> Node s1 a1’
• Probable cause: ‘Node’ is applied to too few arguments
In the expression: Node (state act Root 0 [])
In an equation for ‘createRoot’:
createRoot state act = Node (state act Root 0 [])
• Relevant bindings include
act :: a (bound at Search.hs:43:24)
state :: s (bound at Search.hs:43:18)
createRoot :: s -> a -> Node s a (bound at Search.hs:43:1)
【问题讨论】:
-
对我来说就像一个包围错误。
Node (state act Root 0 [])表示您给Node构造函数1 参数,其值为state act Root 0 []。我相信你的意思是没有括号的:Node state act Root 0 [],这就是你如何将 5 个参数应用于 Haskell 中的函数。 -
Haskell 函数被称为
fun arg1 arg2 arg4,而不是fun (arg1 arg2 arg3)——后者读作fun(arg1(arg2, arg3))。
标签: haskell syntax function-call