From 2ee23016bd51319d111b0f3410e08fb4a81f6135 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sat, 14 Aug 2021 14:17:13 +0300 Subject: [PATCH] remove interlude on `$` --- basics/01-values-and-functions.md | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/basics/01-values-and-functions.md b/basics/01-values-and-functions.md index 3c8e9f1..8bc4e8b 100644 --- a/basics/01-values-and-functions.md +++ b/basics/01-values-and-functions.md @@ -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) @@ -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