Haskell Study Note (Lesson 4)
Haskell Study Note (Lesson 4)
Lesson 4 Conditionals & Branching
Basic if - else Expressions
The basic structure of if-else is :
1 | if conidition |
For example, to judge whether a number is positive :
1 | isPossive :: Int -> String |
Guard in Depth
Basic grammar :
1 | functionName args |
Note that the otherwise (Default Branch) is neccesary.
An example :
1 | isPossive :: Int -> String |
Practice : Smart Shopping Assitant
1 | shoppingAssistant :: Double -> (Double, String) |
Note :
- To use guard, note the place of your =
- To output Triple, you can use print instead of putStrLn
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 zhangxixi的博客!
