Skip to content

Commit eea2f4b

Browse files
Zelenyamilesfrain
authored andcommitted
Update and clarify identity in chapter 10
1 parent ec7e449 commit eea2f4b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

text/chapter10.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,22 +1238,24 @@ is actually represented as a JavaScript string at runtime. This is useful for de
12381238

12391239
### Representing Quantified Types
12401240

1241-
Expressions with quantified (polymorphic) types have restrictive representations at runtime. In practice, this means that there are relatively few expressions with a given quantified type, but that we can reason about them quite effectively.
1241+
Expressions with quantified (polymorphic) types have restrictive representations at runtime. In practice, there are relatively few expressions with a given quantified type, but we can reason about them quite effectively.
12421242

12431243
Consider this polymorphic type, for example:
12441244

12451245
```haskell
12461246
forall a. a -> a
12471247
```
12481248

1249-
What sort of functions have this type? Well, there is certainly one function with this type - namely, the `identity` function, defined in the `Prelude`:
1249+
What sort of functions have this type? Well, there is certainly one function with this type:
12501250

12511251
```haskell
1252-
id :: forall a. a -> a
1253-
id a = a
1252+
identity :: forall a. a -> a
1253+
identity a = a
12541254
```
12551255

1256-
In fact, the `identity` function is the _only_ (total) function with this type! This certainly seems to be the case (try writing an expression with this type which is not observably equivalent to `identity`), but how can we be sure? We can be sure by considering the runtime representation of the type.
1256+
> Note that the actual [`identity`](https://pursuit.purescript.org/packages/purescript-prelude/docs/Control.Category#v:identity) function defined in `Prelude` has a slightly different type.
1257+
1258+
In fact, the `identity` function is the _only_ (total) function with this type! This certainly seems to be the case (try writing an expression with this type that is not observably equivalent to `identity`), but how can we be sure? We can be sure by considering the runtime representation of the type.
12571259

12581260
What is the runtime representation of a quantified type `forall a. t`? Well, any expression with the runtime representation for this type must have the correct runtime representation for the type `t` for any choice of type `a`. In our example above, a function of type `forall a. a -> a` must have the correct runtime representation for the types `String -> String`, `Number -> Number`, `Array Boolean -> Array Boolean`, and so on. It must take strings to strings, numbers to numbers, etc.
12591261

0 commit comments

Comments
 (0)