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
The generated `autogen` directory created contains the generated TypeScript modules.
72
71
73
72
Note that `lbf-list-modules-typescript` is needed to create a JSON object which maps package names (for NPM) to Lambda Buffers' modules.
74
-
Thus, in this example one should have a `package.json` file which associates the key `"name"` with the string value `"lbf-document"`.
73
+
Thus, in this example, one should have a `package.json` file which associates the key `"name"` with the string value `"lbf-document"`.
75
74
76
75
The `autogen/build.json` file can be ignored.
77
76
@@ -149,7 +148,7 @@ where the `...` denotes iterated `SomeTypei` for some `i`, then
149
148
## Sum types
150
149
The types `Author`, `Reviewer`, and `RichContent` have been declared as sum types in the LambdaBuffers schema using the `sum` keyword.
151
150
152
-
In general, sum types are mapped to a [union type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types) in TypeScript and follows the additional following rules.
151
+
In general, sum types are mapped to a [union type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types) in TypeScript and with the additional following rules.
153
152
Given a LambdaBuffers' sum type as follows
154
153
155
154
```purescript
@@ -159,9 +158,7 @@ sum MySum
159
158
|BranchNBranchNType1 ... BranchNTypeMN
160
159
```
161
160
162
-
where the `...` denotes either an iterated `Branchi` for some `i`, or an
163
-
iterated `BranchiTypej` for some `i` and `j`, then each branch, say `Branchi` is translated as
164
-
follows.
161
+
where the `...` denotes either an iterated `Branchi` for some `i`, or an iterated `BranchiTypej` for some `i` and `j`, then each branch, say `Branchi` is translated as follows.
165
162
166
163
- If `Branchi` has no fields i.e., `|Branchi`, then the corresponding TypeScript type's union member is
167
164
@@ -177,8 +174,7 @@ follows.
177
174
}
178
175
```
179
176
180
-
where `<ProducttranslationofBranchiType1 ... BranchiTypeMi>` denotes the
181
-
right hand side of the [product translation](#product-types) of `prodFieldsProduct = BranchiType1 ... BranchiTypeMi`.
177
+
where `<ProducttranslationofBranchiType1 ... BranchiTypeMi>` denotes the right hand side of the [product translation](#product-types) of `prodFieldsProduct = BranchiType1 ... BranchiTypeMi`.
182
178
183
179
So, for example, given `|BranchiBranchiType1`, the corresponding TypeScript type is as follows
184
180
@@ -197,8 +193,7 @@ follows.
197
193
```
198
194
199
195
## Record types
200
-
The types `Document` and `Chapter` have been declared as record types in the
201
-
LambdaBuffers schema using the `record` keyword.
196
+
The types `Document` and `Chapter` have been declared as record types in the LambdaBuffers schema using the `record` keyword.
202
197
203
198
Record types are mapped to [object types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#object-types) in TypeScript.
204
199
Given a LambdaBuffers' record type as follows
@@ -218,15 +213,15 @@ TypeScript has no builtin implementation of type classes. As such, LambdaBuffers
218
213
A complete usage example can be found in the [TypeScript Prelude sample project](./typescript-prelude/src/index.mts).
219
214
220
215
A type class in TypeScript is an object type which defines a set of methods.
221
-
For example, the `Eq` type class in Haskell defines `==` (equality) and `/=` (inequality) as follows.
216
+
For example, the `Eq` type class in Haskell defines the set of methods `==` (equality) and `/=` (inequality) as follows.
222
217
223
218
```haskell
224
219
classEqawhere
225
220
(==) :: a -> a -> Bool
226
221
(/=) :: a -> a -> Bool
227
222
```
228
223
229
-
Thus, the [`Eq` class](https://github.com/mlabs-haskell/prelude-typescript/blob/main/src/Lib/Eq.ts) in TypeScript is:
224
+
Thecorresponding [`Eq` class](https://github.com/mlabs-haskell/prelude-typescript/blob/main/src/Lib/Eq.ts) in TypeScript is:
230
225
231
226
```ts
232
227
exportinterfaceEq<A> {
@@ -302,9 +297,7 @@ This loosely follows the original translation given in the paper [How to make ad
302
297
303
298
## Limitations
304
299
305
-
- Only Haskell 2010 typeclasses are supported for the TypeScript code
306
-
generator. So, the following schemas will probably generate incorrect
307
-
code.
300
+
- Only Haskell 2010 typeclasses are supported for the TypeScript code generator. So, the following schemas will probably generate incorrect code.
0 commit comments