Search code examples
haskellsyntaxfunction-call

"‘Node’ is applied to too few arguments" even though there are exact number


s and a are type variables. In the constructor the first two param are the data, then its parent, its level in the graph and then a list of its children.

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

And I've passed the exact same amount of 5 arguments to Node constructor, however I'm getting errors.

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

Solution

  • Parentheses are used for grouping expressions. (length "hello" + 2) is a single value, not 4.

    Similarly, Node (...) applies Node to a single argument: (state act Root 0 []). Obviously that's wrong (and would require state to be a function taking four arguments).

    The solution is to just remove the parentheses:

    Node state act Root 0 []
    

    Now Node is applied to five arguments.