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: text/chapter6.md
+41-3Lines changed: 41 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -47,9 +47,47 @@ instance Show Boolean where
47
47
show false ="false"
48
48
```
49
49
50
-
This code declares a type class instance called `showBoolean` – in PureScript, type class instances can be named to aid the readability of the generated JavaScript. We say that the `Boolean` type _belongs to the `Show` type class_.
51
-
52
-
We can try out the `Show` type class in PSCi, by showing a few values with different types:
50
+
This code declares a type class instance; we say that the `Boolean` type _belongs to the `Show` type class_.
51
+
52
+
> If you're wondering, the generated JS code looks like this:
53
+
>
54
+
> ```javascript
55
+
>var showBoolean = {
56
+
>show:function (v) {
57
+
>if (v) {
58
+
>return"true";
59
+
> };
60
+
>if (!v) {
61
+
>return"false";
62
+
> };
63
+
>thrownewError("Failed pattern match at ...");
64
+
> }
65
+
> };
66
+
>```
67
+
>
68
+
> If you're unhappy with the generated name, you can give names to type class instances. For example:
69
+
>
70
+
> ```haskell
71
+
> instance myShowBoolean :: Show Boolean where
72
+
> show true="true"
73
+
> show false="false"
74
+
>```
75
+
>
76
+
> ```javascript
77
+
>var myShowBoolean = {
78
+
>show:function (v) {
79
+
>if (v) {
80
+
>return"true";
81
+
> };
82
+
>if (!v) {
83
+
>return"false";
84
+
> };
85
+
>thrownewError("Failed pattern match at ...");
86
+
> }
87
+
> };
88
+
>```
89
+
90
+
We can try out the `Show` type class in PSCi by showing a few values with different types:
0 commit comments