Running Code Conditionally Using Branches
Haskell supports quite a few ways to take different branches in your code. Some, like the venerable if expression will look familiar. Others, like guard clauses might not. In this section, you’ll learn the basics of branching in your program. Later, here, you’ll learn about pattern matching, a powerful technique you can combine with branches to make your code incredibly expressive.
The branching structure that you’re probably most familiar with from other languages is the if expression. Like most other languages, if expressions in Haskell allow you to return one value if some predicate is true, and a different value if the predicate is false. In Haskell, if structures are expressions, meaning that you ...
Get Effective Haskell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.