Hello,
I am new to Haskell and trying to learn it with
learnyouahaskell.com and Pluralsight Haskell course.
And i have a very noob question.
I understand that if .. else is just a syntactic sugar over case. But what about guards then ?
Are guards also case in different syntax ? Or vice versa ? Like with an example.
anyEven nums
| (length (removeOdd nums)) > 0 = True
| otherwise = False
anyEven' nums = case (removeOdd nums) of
[] -> False
(x:xs) -> True
I can do the same thing with both of them.
As i understand the only different thing is, with case i can manipulate the parameter (like here in the example i used removeOdd) and can use the manipulated parameter to decide what to do after that.
So i will not need to use removeOdd function inside the case. ( maybe i will need to use in every guard definition if i choose to use guards )
Is this it?
Is this the only difference between them ?
And if it is, why haskell needed do implement both of them. Can't we use function like removeOdd before using it on case or guard functions ?
Thanks, and sorry if my english is bad.
Semih Masat