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

问题描述 投票:0回答:1

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)
haskell syntax function-call
1个回答
7
投票

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

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

解决方案是删除括号:

Node state act Root 0 []

现在Node适用于五个论点。

© www.soinside.com 2019 - 2024. All rights reserved.