You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we apply the function `landLeft 1` to `(0,0)` we get `(1,0)`.
350
350
Then, we land a bird on the right side, resulting in `(1,1)`.
351
351
Finally two birds land on the left side, resulting in `(3,1)`.
352
-
We apply a function to something by first writing the function and then writing its parameter, but here it would be better if the pole went first and then the landing function.
352
+
We apply a function to something by first writing the function and then writing its argument, but here it would be better if the pole went first and then the landing function.
353
353
If we make a function like this:
354
354
355
355
```{.haskell:hs}
356
356
x -: f = f x
357
357
```
358
358
359
-
We can apply functions by first writing the parameter and then the function:
359
+
We can apply functions by first writing the argument and then the function:
360
360
361
361
```{.haskell:hs}
362
362
ghci> 100 -: (*3)
@@ -498,7 +498,7 @@ Now that we have a `Nothing`, it gets fed to `landRight (-2)`, but because it's
498
498
499
499
We couldn't have achieved this by just using `Maybe` as an applicative.
500
500
If you try it, you'll get stuck, because applicative functors don't allow for the applicative values to interact with each other very much.
501
-
They can, at best, be used as parameters to a function by using the applicative style.
501
+
They can, at best, be used as arguments to a function by using the applicative style.
502
502
The applicative operators will fetch their results and feed them to the function in a manner appropriate for each applicative and then put the final applicative value together, but there isn't that much interaction going on between them.
503
503
Here, however, each step relies on the previous one's result.
504
504
On every landing, the possible result from the previous one is examined and the pole is checked for balance.
@@ -531,7 +531,7 @@ Instead of making functions that ignore their input and just return a predetermi
531
531
m >> n = m >>= \_ -> n
532
532
```
533
533
534
-
Normally, passing some value to a function that ignores its parameter and always just returns some predetermined value would always result in that predetermined value.
534
+
Normally, passing some value to a function that ignores its argument and always just returns some predetermined value would always result in that predetermined value.
535
535
With monads however, their context and meaning has to be considered as well.
536
536
Here's how `>>` acts with `Maybe`:
537
537
@@ -678,7 +678,7 @@ ghci> Just 9 >>= (\x -> Just (x > 8))
678
678
Just True
679
679
```
680
680
681
-
Because the left parameter of`>>=` is a `Just` value, the lambda is applied to `9` and the result is a `Just True`.
681
+
Because the left argument to`>>=` is a `Just` value, the lambda is applied to `9` and the result is a `Just True`.
682
682
If we rewrite this in `do` notation, we get:
683
683
684
684
```{.haskell:hs}
@@ -1295,7 +1295,7 @@ Composing two functions is implemented like so:
1295
1295
f . g = (\x -> f (g x))
1296
1296
```
1297
1297
1298
-
If the type of `g` is `a -> b` and the type of `f` is `b -> c`, we arrange them into a new function which has a type of `a -> c`, so that its parameter is passed between those functions.
1298
+
If the type of `g` is `a -> b` and the type of `f` is `b -> c`, we arrange them into a new function which has a type of `a -> c`, so that its argument is passed between those functions.
1299
1299
Now what if those two functions were monadic, that is, what if the values they returned were monadic values?
1300
1300
If we had a function of type `a -> m b`, we couldn't just pass its result to a function of type `b -> m c`, because that function accepts a normal `b`, not a monadic one.
Copy file name to clipboardExpand all lines: source_md/for-a-few-monads-more.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -668,7 +668,7 @@ instance Monad ((->) r) where
668
668
669
669
We've already seen how `pure` is implemented for functions, and `return` is pretty much the same thing as `pure`.
670
670
It takes a value and puts it in a minimal context that always has that value as its result.
671
-
And the only way to make a function that always has a certain value as its result is to make it completely ignore its parameter.
671
+
And the only way to make a function that always has a certain value as its result is to make it completely ignore its argument.
672
672
673
673
The implementation for `>>=` seems a bit cryptic, but it's really not all that.
674
674
When we use `>>=` to feed a monadic value to a function, the result is always a monadic value.
@@ -722,8 +722,8 @@ addStuff x = let
722
722
723
723
We see that the reader monad allows us to treat functions as values with a context.
724
724
We can act as if we already know what the functions will return.
725
-
It does this by gluing functions together into one function and then giving that function's parameter to all of the functions that it was glued from.
726
-
So if we have a lot of functions that are all just missing one parameter and they'd eventually be applied to the same thing, we can use the reader monad to sort of extract their future results and the `>>=` implementation will make sure that it all works out.
725
+
It does this by gluing functions together into one function and then giving that function's argument to all of the functions that it was glued from.
726
+
So if we have a lot of functions that are all just missing one argument and they'd eventually be applied to the same thing, we can use the reader monad to sort of extract their future results and the `>>=` implementation will make sure that it all works out.
727
727
728
728
## Tasteful stateful computations {#state}
729
729
@@ -735,7 +735,7 @@ However, some problems are inherently stateful in that they rely on some state t
735
735
While such problems aren't a problem for Haskell, they can be a bit tedious to model sometimes.
736
736
That's why Haskell features a thing called the state monad, which makes dealing with stateful problems a breeze while still keeping everything nice and pure.
737
737
738
-
[When we were dealing with random numbers](input-and-output.html#randomness), we dealt with functions that took a random generator as a parameter and returned a random number and a new random generator.
738
+
[When we were dealing with random numbers](input-and-output.html#randomness), we dealt with functions that took a random generator as an argument and returned a random number and a new random generator.
739
739
If we wanted to generate several random numbers, we always had to use the random generator that a previous function returned along with its result.
740
740
When making a function that takes a `StdGen` and tosses a coin three times based on that generator, we had to do this:
741
741
@@ -1219,7 +1219,7 @@ Using this applicative style makes things pretty easy.
1219
1219
1220
1220
So it's kind of like `fmap`, only the function itself is in a context.
1221
1221
We have to somehow extract it from the context and map it over the `f a` value and then assemble the context back together.
1222
-
Because all functions are curried in Haskell by default, we can use the combination of `<$>` and `<*>` to apply functions that take several parameters between applicative values.
1222
+
Because all functions are curried in Haskell by default, we can use the combination of `<$>` and `<*>` to apply functions that take several arguments between applicative values.
1223
1223
1224
1224
Anyway, it turns out that just like `fmap`, `<*>` can also be implemented by using only what the `Monad` type class gives us.
1225
1225
The `ap` function is basically `<*>`, only it has a `Monad` constraint instead of an `Applicative` one.
Copy file name to clipboardExpand all lines: source_md/functionally-solving-problems.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,10 +44,10 @@ Finally, there's a `-`.
44
44
We pop `10` and `14` from the stack, subtract `14` from `10` and push that back.
45
45
The number on the stack is now `-4` and because there are no more numbers or operators in our expression, that's our result!
46
46
47
-
Now that we know how we'd calculate any RPN expression by hand, let's think about how we could make a Haskell function that takes as its parameter a string that contains an RPN expression, like `"10 4 3 + 2 * -"` and gives us back its result.
47
+
Now that we know how we'd calculate any RPN expression by hand, let's think about how we could make a Haskell function that takes as its argument a string that contains an RPN expression, like `"10 4 3 + 2 * -"` and gives us back its result.
48
48
49
49
What would the type of that function be?
50
-
We want it to take a string as a parameter and produce a number as its result.
50
+
We want it to take a string as an argument and produce a number as its result.
51
51
So it will probably be something like `solveRPN :: (Num a) => String -> a`.
0 commit comments