Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions message-index/messages/GHC-01239/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ introduced: 9.6.1
Unlike in many other languages, in Haskell the If-Then-Else construct is an expression, which means it returns a value that can be processed further.

```haskell
ageMessage :: Int -> String
ageMessage age = if age < 18 then "You are too young to enter" else "Welcome to the club"
greetUser :: Int -> IO ()
greetUser age = putStrLn (if age < 18
then "You are too young to enter"
else "Welcome to the club")

putStrLn (ageMessage 10) -- You are too young to enter
putStrLn (ageMessage 20) -- Welcome to the club
greetUser 10 -- You are too young to enter
greetUser 20 -- Welcome to the club
```

Because If-Then-Else expressions return values, it makes sense to pass them as input to a function.
Expand Down