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

Cru*_*lad 0 syntax haskell 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 [])
Run Code Online (Sandbox Code Playgroud)

我已经将完全相同的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)
Run Code Online (Sandbox Code Playgroud)

mel*_*ene 7

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

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

解决方法是只删除括号:

Node state act Root 0 []
Run Code Online (Sandbox Code Playgroud)

现在Node应用于五个参数。