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
Copy file name to clipboardExpand all lines: source_md/for-a-few-monads-more.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1221,7 +1221,7 @@ 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
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.
1223
1223
1224
-
Anyway, it turns out that just like `fmap`, `<*>` can also be implemented by using only what the `Monad` type class give us.
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/higher-order-functions.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,7 +165,7 @@ The second parameter is something of that type also and the return value is also
165
165
We could read this type declaration in the curried way, but to save ourselves a headache, we'll just say that this function takes two parameters and returns one thing.
166
166
The first parameter is a function (of type `a -> a`) and the second is that same `a`.
167
167
The function can also be `Int -> Int` or `String -> String` or whatever.
168
-
But then, the second parameter to also has to be of that type.
168
+
But then, the second parameter has to also be of that type.
169
169
170
170
::: {.hintbox}
171
171
**Note:** From now on, we'll say that functions take several parameters despite each function actually taking only one parameter and returning partially applied functions until we reach a function that returns a solid value.
@@ -248,7 +248,7 @@ flip' f = g
248
248
where g x y = f y x
249
249
```
250
250
251
-
Reading the type declaration, we say that it takes a function that takes an `a` and a `b` and returns a function that takes a `b` and an `a`.
251
+
Reading the type declaration, we see that it takes a function that takes an `a` and a `b` and returns a function that takes a `b` and an `a`.
252
252
But because functions are curried by default, the second pair of parentheses is really unnecessary, because `->` is right associative by default.
253
253
`(a -> b -> c) -> (b -> a -> c)` is the same as `(a -> b -> c) -> (b -> (a -> c))`, which is the same as `(a -> b -> c) -> b -> a -> c`.
254
254
We wrote that `g x y = f y x`.
@@ -336,7 +336,7 @@ ghci> filter (`elem` ['A'..'Z']) "i Laugh At you Because u R All The Same"
336
336
```
337
337
338
338
All of this could also be achieved with list comprehensions by the use of predicates.
339
-
There's no set rule for when to use `map` and `filter` versus using list comprehension, you just have to decide what's more readable depending on the code and the context.
339
+
There's no set rule for when to use `map` and `filter` versus using a list comprehension, you just have to decide what's more readable depending on the code and the context.
340
340
The `filter` equivalent of applying several predicates in a list comprehension is either filtering something several times or joining the predicates with the logical `&&` function.
341
341
342
342
Remember our quicksort function from the [previous chapter](recursion.html)?
Our data type is good, although it could be better.
@@ -1871,7 +1871,8 @@ data Frank a b = Frank {frankField :: b a} deriving (Show)
1871
1871
How do we know this type has a kind of `k -> (k -> *) - > *`?
1872
1872
Well, fields in ADTs are made to hold values, so they must be of kind `*`, obviously.
1873
1873
We assume `k` for `a`, and `b` takes it as its argument so its kind is `k -> *`.
1874
-
Now we know the kinds of both `a` and `b` and because they're parameters for `Frank`, we see that `Frank` has a kind of `k -> (k -> *) -> *` The first `k` represents `a` and the `(k -> *)` represents `b`.
1874
+
Now we know the kinds of both `a` and `b` and because they're parameters for `Frank`, we see that `Frank` has a kind of `k -> (k -> *) -> *`.
1875
+
The first `k` represents `a` and the `(k -> *)` represents `b`.
1875
1876
Let's make some `Frank` values and check out their types.
Copy file name to clipboardExpand all lines: source_md/modules.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
@@ -408,7 +408,7 @@ find :: (a -> Bool) -> [a] -> Maybe a
408
408
409
409
Notice the type of `find`.
410
410
Its result is `Maybe a`.
411
-
That's kind of like having the type of `[a]`, only a value of the type `Maybe` can contain either no elements or one element, whereas a list can contain no elements, one element or several elements.
411
+
That's kind of like having the type of `[a]`, only a value of the type `Maybe a` can contain either no elements or one element, whereas a list can contain no elements, one element or several elements.
412
412
413
413
Remember when we were searching for the first time our stock went over $1000.
414
414
We did `head (dropWhile (\(val,y,m,d) -> val < 1000) stock)`.
`insert`{.label .function} takes an element and a list of elements that can be sorted and inserts it into the last position where it's still less than or equal to the next element.
562
-
In other words, `insert` will start at the beginning of the list and then keep going until it finds an element that's equal to or greater than the element that we're inserting and it will insert it just before the element.
562
+
In other words, `insert` will start at the beginning of the list and then keep going until it finds an element that's equal to or greater than the element that we're inserting and it will insert it just before that element.
563
563
564
564
```{.haskell:ghci}
565
565
ghci> insert 4 [3,5,1,2,8,2]
@@ -743,7 +743,7 @@ ghci> filter (not . any isSpace) . groupBy ((==) `on` isSpace) $ "hey folks its
743
743
744
744
Ah.
745
745
746
-
The `Data.Char` also exports a datatype that's kind of like `Ordering`.
746
+
The `Data.Char`module also exports a datatype that's kind of like `Ordering`.
747
747
The `Ordering` type can have a value of `LT`, `EQ` or `GT`.
748
748
It's a sort of enumeration.
749
749
It describes a few possible results that can arise from comparing two elements.
@@ -798,7 +798,7 @@ ghci> intToDigit 5
798
798
'5'
799
799
```
800
800
801
-
The `ord`{.label .function} and `chr` functions convert characters to their corresponding numbers and vice versa:
801
+
The `ord`{.label .function} and `chr`{.label .function} functions convert characters to their corresponding numbers and vice versa:
802
802
803
803
```{.haskell:ghci}
804
804
ghci> ord 'a'
@@ -960,7 +960,7 @@ fromList [(1,2),(3,2),(5,5)]
960
960
```
961
961
962
962
If there are duplicate keys in the original association list, the duplicates are just discarded.
963
-
This is the type signature of `fromList`
963
+
This is the type signature of `fromList`:
964
964
965
965
```{.haskell:hs}
966
966
Map.fromList :: (Ord k) => [(k, v)] -> Map.Map k v
0 commit comments