Jackson Zhu
Jackson Zhu

Reputation: 29

how to make function have different numbers of arguments

buyItem :: Hero -> Item -> Hero

buyItem (Mage n Wealth Gold) item1 = (Mage n Wealth item1)

buyItem (Warrior a item)
    | enough (Warrior a c) >= cost item = (Warrior a c++item)
    | otherwise = (Warrior a c)

buyItem (Mage a b c) item
    | enough (Mage a b c) >= cost item = (Mage a b item)
    | otherwise = (Mage a b c)

RPGdefs.hs:136:1: error:
    Equations for ‘buyItem’ have different numbers of arguments
      RPGdefs.hs:136:1-58
      RPGdefs.hs:(137,1)-(139,31)
    |
136 | buyItem (Mage n Wealth Gold) item1 = (Mage n Wealth item1)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Failed, no modules loaded.

Upvotes: 0

Views: 65

Answers (1)

Fyodor Soikin
Fyodor Soikin

Reputation: 80915

You have a typo here:

buyItem (Warrior a item)

It should be this:

buyItem (Warrior a) item

When you write (Warrior a item), it means that item is part of Warrior, but from the rest of your code it looks like Warrior should be first parameter and item should be second. That's how the other two cases (the ones with Mage) are written.

Upvotes: 2

Related Questions