Skip to content

Commit 66fcdc2

Browse files
Apply change suggestions
Co-authored-by: Thomas Honeyman <[email protected]>
1 parent 7c3c841 commit 66fcdc2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

language/Type-Classes.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ tenPoints :: Score
181181
tenPoints = (Score 4) + (Score 6)
182182
```
183183

184-
That `derive` line replaced all this code!:
184+
That `derive` line replaced all this code:
185185

186186
```purs
187187
-- No need to write this
@@ -222,7 +222,9 @@ main = logShow [Some, Arbitrary 1, Contents 2.0 "Three"]
222222
-- [Some,(Arbitrary 1),(Contents 2.0 "Three")]
223223
```
224224

225-
Note that the `show` output string can be copy-pasted to reconstruct the original data. This is a good oportunity to emphasize how `newtype` deriving simply reuses the instance of the underlying type. In the case of `show`, this means omitting printing the wrapper.
225+
The `Show` type class is most often used for debugging data, so the output of most `Show` instances can be copy-pasted back into a PureScript source file to reconstruct the original data. The `Show` instance we created by deriving `Generic` and then using `genericShow` follows this convention.
226+
227+
This is a good opportunity to emphasize how newtype deriving is different from instances derived by the compiler or through the `Generic` type class. In the examples below, notice how the instance derived through `Generic` includes the newtype constructor `Score`, but the newtype-derived instance simply reuses the underlying `Show` instance for `Int` and therefore does not include the constructor:
226228

227229
```purs
228230
import Effect.Console (logShow)

0 commit comments

Comments
 (0)