即使有确切的数字,““节点”也应用到的参数太少”

时间:2019-04-16 21:22:55

标签: haskell syntax function-call

sa是类型变量。 在构造函数中,前两个参数是数据,然后是父级,是图形中的级别,然后是其子级列表。

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 [])

我已经向Node构造函数传递了完全相同的5个参数,但是我遇到了错误。

• 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)

1 个答案:

答案 0 :(得分:7)

括号用于对表达式进行分组。 (length "hello" + 2)是单个值,而不是4。

类似地,Node (...)Node应用于单个参数:(state act Root 0 [])。显然这是错误的(并且需要state是一个带有四个参数的函数)。

解决方案是只删除括号:

Node state act Root 0 []

现在Node应用于五个参数。