Skip to content

Commit

Permalink
remove interlude on $
Browse files Browse the repository at this point in the history
  • Loading branch information
GoNZooo committed Aug 14, 2021
1 parent b4ed484 commit 2ee2301
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions basics/01-values-and-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- [Guards](#guards)
- [Exercises (Asking questions about values)](#exercises-asking-questions-about-values)
- [Exercise notes (Asking questions about values)](#exercise-notes-asking-questions-about-values)
- [Interlude: Function application with `$`](#interlude-function-application-with-)
- [Partial application](#partial-application)
- [Exercises (Partial application)](#exercises-partial-application)
- [Exercise notes (Partial application)](#exercise-notes-partial-application)
Expand Down Expand Up @@ -339,35 +338,6 @@ clause.

#### Exercise notes (Asking questions about values)

## Interlude: Function application with `$`

Sometimes you'll want to apply a function and you'll need to parenthesize the expression in order
to do it:

```haskell
safeDivide :: Int -> Int -> DivisionResult
safeDivide _x 0 = DivisionByZero
safeDivide x divisor =
let xAsFloat = fromIntegral x
divisorAsFloat = fromIntegral divisor
-- We want to apply the `DivideSuccess` constructor here to the result of the
-- division, not just `xAsFloat`, so we parenthesize the calculation.
in DivideSuccess (xAsFloat / divisorAsFloat)
```

The above can be written using the `$` operator, which applies the function on the left to the
expression on the right:

```haskell
safeDivide :: Int -> Int -> DivisionResult
safeDivide _x 0 = DivisionByZero
safeDivide x divisor =
let xAsFloat = fromIntegral x
divisorAsFloat = fromIntegral divisor
-- With `$` we no longer need to parenthesize the expression.
in DivideSuccess $ xAsFloat / divisorAsFloat
```

## Partial application

When you apply a function, you can choose to **not** pass all the arguments it's expecting. This
Expand Down

0 comments on commit 2ee2301

Please sign in to comment.