answerFalse::Int->IO()
answerFalse hp=do
hp--
if hp<=0 then
putStrLn"================Game Over================"
else
print(hp)
i already declare hp as int with value 3
now my problem is when i put “hp–“, it shows error
Couldn't match expected type `IO a0' with actual type `Int'
but if i put “–hp”, the result print is 3 not 2.
i also tried let hp=hp-1, the system stuck there.
You can’t modify variables in Haskell.
hp++and++hp(orhp--and--hp) don’t work in Haskell at all; the reason why--hpcompiles is that--creates a comment which comments out thehppart.What you are trying to do is this:
You can also do it like this, by creating a new variable:
You need to review your basic Haskell knowledge by reading beginner tutorials. This question provides excellent resources for you.