Skip to content

Commit

Permalink
add minor section about $
Browse files Browse the repository at this point in the history
  • Loading branch information
GoNZooo committed Aug 17, 2021
1 parent 2b68067 commit 0be95b1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions basics/01-values-and-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Guards](#guards)
- [Exercises (Asking questions about values)](#exercises-asking-questions-about-values)
- [Exercise notes (Asking questions about values)](#exercise-notes-asking-questions-about-values)
- [`$` for function application](#-for-function-application)
- [Partial application](#partial-application)
- [Exercises (Partial application)](#exercises-partial-application)
- [Exercise notes (Partial application)](#exercise-notes-partial-application)
Expand Down Expand Up @@ -339,6 +340,23 @@ clause.

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

## `$` for function application

Sometimes you will see a dollar sign operator (`$`) in code. This is actually a utility operator
meant for function application:

```haskell
f :: Int -> String
f x = show (deriveFlorbFactorFromMerkleNumber (castToMerkleNumber x))

f' :: Int -> String
f' x = show $ deriveFlorbFactorFromMerkleNumber $ castToMerkleNumber x
```

As you can see from the above snippet, using `$` allows us to just say "Apply the function on the
left to the expression on the right". `$` binds tightly to the right, so the parenthesis we see
above is what will be by default, hence we have no need for parenthesis like this when we use `$`.

## 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 0be95b1

Please sign in to comment.