So I am making a function that I want to call, print a string depending on the value (with guards), and then call that same function again with different values.
This is what I was thinking
something a
| a <= 1 = "One" && (something (a 1))
| a == 2 = "Two" && something (a 1)
| a >= 3 = "Three" && something (a 1)
| otherwise = something a
I know this is an endless loop and I know this is wrong but it's just the idea I had.
Any idea to make this would be appreciated.
CodePudding user response:
You should change the "&&" , instead use the " ". Try this:
something :: Integer -> String
something a | a <= 1 = "One" something (a 1)
| a == 2 = "Two" something (a 1)
| a >= 3 = "Three" something (a 1)
| otherwise = something a
main = do
putStrLn "Result:"
print (something 1)