Skip to content

Commit 0ef208d

Browse files
authored
Update kind info in types (#447)
1 parent 8bcd61e commit 0ef208d

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

text/chapter3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ $ spago repl
371371
> import Data.List
372372
> :type Cons
373373
374-
forall a. a -> List a -> List a
374+
forall (a :: Type). a -> List a -> List a
375375
```
376376

377377
This type signature says that `Cons` takes a value of some type `a`, takes a list of elements of type `a`, and returns a new list with entries of the same type. Let's specialize this with `a` as our `Entry` type:
@@ -506,11 +506,11 @@ $ spago repl
506506
> import Data.List
507507
> :type filter
508508
509-
forall a. (a -> Boolean) -> List a -> List a
509+
forall (a :: Type). (a -> Boolean) -> List a -> List a
510510
511511
> :type head
512512
513-
forall a. List a -> Maybe a
513+
forall (a :: Type). List a -> Maybe a
514514
```
515515

516516
Let's pick apart these two types to understand their meaning.

text/chapter4.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ Let's look at the type of `map`:
112112

113113
```text
114114
> :type map
115-
forall a b f. Functor f => (a -> b) -> f a -> f b
115+
forall (f :: Type -> Type) (a :: Type) (b :: Type). Functor f => (a -> b) -> f a -> f b
116116
```
117117

118118
The type of `map` is actually more general than we need in this chapter. For our purposes, we can treat `map` as if it had the following less general type:
119119

120120
```text
121-
forall a b. (a -> b) -> Array a -> Array b
121+
forall (a :: Type) (b :: Type). (a -> b) -> Array a -> Array b
122122
```
123123

124124
This type says that we can choose any two types, `a` and `b`, with which to apply the `map` function. `a` is the type of elements in the source array, and `b` is the type of elements in the target array. In particular, there is no reason why `map` has to preserve the type of the array elements. We can use `map` or `<$>` to transform integers to strings, for example:
@@ -195,7 +195,7 @@ Another standard function on arrays is the `concat` function, defined in `Data.A
195195
> import Data.Array
196196
197197
> :type concat
198-
forall a. Array (Array a) -> Array a
198+
forall (a :: Type). Array (Array a) -> Array a
199199
200200
> concat [[1, 2, 3], [4, 5], [6]]
201201
[1, 2, 3, 4, 5, 6]
@@ -209,7 +209,7 @@ Let's see it in action:
209209
> import Data.Array
210210
211211
> :type concatMap
212-
forall a b. (a -> Array b) -> Array a -> Array b
212+
forall (a :: Type) (b :: Type). (a -> Array b) -> Array a -> Array b
213213
214214
> concatMap (\n -> [n, n * n]) (1 .. 5)
215215
[1,1,2,4,3,9,4,16,5,25]
@@ -335,7 +335,7 @@ Just like `pure`, we can apply the `guard` function in PSCi to understand how it
335335
> import Control.Alternative
336336
337337
> :type guard
338-
forall m. Alternative m => Boolean -> m Unit
338+
forall (m :: Type -> Type). Alternative m => Boolean -> m Unit
339339
```
340340

341341
In our case, we can assume that PSCi reported the following type:
@@ -377,19 +377,19 @@ Start by importing the `Data.Foldable` module and inspecting the types of the `f
377377
> import Data.Foldable
378378
379379
> :type foldl
380-
forall a b f. Foldable f => (b -> a -> b) -> b -> f a -> b
380+
forall (f :: Type -> Type) (a :: Type) (b :: Type). Foldable f => (b -> a -> b) -> b -> f a -> b
381381
382382
> :type foldr
383-
forall a b f. Foldable f => (a -> b -> b) -> b -> f a -> b
383+
forall (f :: Type -> Type) (a :: Type) (b :: Type). Foldable f => (a -> b -> b) -> b -> f a -> b
384384
```
385385

386-
These types are more general than we are interested in right now. For this chapter, we can assume that PSCi has given the following (more specific) answer:
386+
These types are more general than we are interested in right now. For this chapter, we can simplify and assume the following (more specific) type signatures:
387387

388388
```text
389-
> :type foldl
389+
-- foldl
390390
forall a b. (b -> a -> b) -> b -> Array a -> b
391391
392-
> :type foldr
392+
-- foldr
393393
forall a b. (a -> b -> b) -> b -> Array a -> b
394394
```
395395

text/chapter5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Record patterns provide a good example of an interesting feature of the PureScri
154154
> showPerson { first: x, last: y } = y <> ", " <> x
155155
156156
> :type showPerson
157-
forall r. { first :: String, last :: String | r } -> String
157+
forall (r :: Row Type). { first :: String, last :: String | r } -> String
158158
```
159159

160160
What is the type variable `r` here? Well, if we try `showPerson` in PSCi, we see something interesting:

text/chapter6.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ To see this, try using one of the standard type classes like `Semiring` in PSCi:
381381
> import Prelude
382382
383383
> :type \x -> x + x
384-
forall a. Semiring a => a -> a
384+
forall (a :: Type). Semiring a => a -> a
385385
```
386386

387387
Here, we might have annotated this function as `Int -> Int` or `Number -> Number`, but PSCi shows us that the most general type works for any `Semiring`, allowing us to use our function with both `Int`s and `Number.
@@ -540,7 +540,7 @@ This hint is enough for the compiler to infer the correct type for our generic t
540540

541541
```text
542542
> :type genericTail
543-
forall stream element. Stream stream element => stream -> Maybe stream
543+
forall (stream :: Type) (element :: Type). Stream stream element => stream -> Maybe stream
544544

545545
> genericTail "testing"
546546
(Just "esting")

text/chapter7.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ It is instructive to look at the type of `lift3`:
8686

8787
```text
8888
> :type lift3
89-
forall a b c d f. Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
89+
forall (a :: Type) (b :: Type) (c :: Type) (d :: Type) (f :: Type -> Type). Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
9090
```
9191

9292
In the `Maybe` example above, the type constructor `f` is `Maybe`, so that `lift3` is specialized to the following type:

0 commit comments

Comments
 (0)