I'm new to Haskell and I'm trying to figure out how to add without having to use the '+' sign. I'm using Winhugs as a compiler.
Let's say, cookies = 10, chocolate = 5, cake = 20
if I enter,
cookies 1 chocolate 1
output should be,
15
here's what I have
cookies :: Int -> Int
cookies 1 = 10
cookies n = 10 + cookies (n-1)
chocolate :: Int -> Int
chocolate 1 = 5
chocolate n = 5 + chocolate (n-1)
i have to enter,
cookies 1 + chocolate 1
in order to get 15. Is there another way around this?
I also tried using recursive types but I still find it very confusing. I tried this one too but I can only add two items and I'd always have to input cookies:
cookies :: Int -> (Int -> Int) -> Int -> Int
cookies x item y = (x * 20) + item y
cake :: Int -> Int
cake 1 = 20
cake n = 20 + cake (n-1)
chocolate :: Int -> Int
chocolate 1 = 5
chocolate n = 5 + chocolate (n-1)
also, I cannot enter just cookies as it should always have another item with it.
cookies 1
ERROR - Cannot find "show" function for:
*** Expression : cookies 1
*** Of type : (Int -> Int) -> Int -> Int
I'm sorry for the very noob question. Thank you to everyone who can help!
** UPDATE ** I know I could use a different compiler but it's what's being taught in school and it's the compiler we need to use for our project as well :(