Skip to content

Commit 538186e

Browse files
author
jared
committed
Updated docs/haskell.md and docs/purescript.md to reflect the
updated frontend tools
1 parent 9b3132b commit 538186e

File tree

3 files changed

+73
-149
lines changed

3 files changed

+73
-149
lines changed

docs/examples/Document.lbf

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Document
22

3+
-- We need the opaque Char type
4+
import Prelude (Char)
5+
36
-- Author
47
sum Author = Ivan | Jovan | Savo
58

@@ -35,14 +38,5 @@ prod RichDocument = (Document RichContent)
3538
-- ## We need a list type
3639
sum List a = Nil | Cons a (List a)
3740

38-
-- ## We need a Char type that is either a letter, number or punctuation
39-
sum Char = Letter Letter | Number Number | Punctuation Punctuation
40-
41-
sum Letter = A | B | C
42-
43-
sum Number = Num0 | Num1 | Num2
44-
45-
sum Punctuation = Dot | Question
46-
4741
-- ## String
48-
prod String = (List Char)
42+
prod String = (List Char)

docs/haskell.md

Lines changed: 49 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,30 @@
33
Let's take a look at how LambdaBuffers modules map into Haskell modules and how
44
LambdaBuffers type definitions map into Haskell type definitions.
55

6-
Note that in this chapter we work with a 'pure' LambdaBuffers module, no
7-
`opaque`s or type clasess, to demonstrate how pure type definition mapping
8-
works.
9-
10-
We'll use the `lbf-to-haskell` CLI tool which is just a convenient wrapper over
6+
We'll use the `lbf-prelude-to-haskell` CLI tool which is just a convenient wrapper over
117
the raw `lbf` CLI. We can get this tool by either loading the LambdaBuffers Nix
128
environment that comes packaged with all the CLI tools:
139

1410
```shell
1511
$ nix develop github:mlabs-haskell/lambda-buffers#lb
16-
$ lb<tab>
17-
lbc lbf lbg lbg-purescript lbg-haskelll lbf-to-purescript lbf-to-haskell
12+
$ lbf<tab>
13+
lbf lbf-plutus-to-purescript lbf-prelude-to-purescript
14+
lbf-plutus-to-haskell lbf-prelude-to-haskell
1815
```
1916

20-
Or we can simply just refer directly to the `lbf-to-haskell` CLI by `nix run
21-
github:mlabs-haskell/lambda-buffers#lbf-to-haskell`.
17+
Or we can simply just refer directly to the `lbf-prelude-to-haskell` CLI by `nix run
18+
github:mlabs-haskell/lambda-buffers#lbf-prelude-to-haskell`.
2219

2320
In this chapter, we're going to use the latter option.
2421

25-
Let's now use `lbf-to-haskell` to process the
26-
27-
[Document.lbf](examples/Document.lbf) schema
22+
Let's now use `lbf-prelude-to-haskell` to process the [Document.lbf](examples/Document.lbf) schema.
2823

2924
```purescript
3025
module Document
3126
27+
-- We need the opaque Char type
28+
import Prelude (Char)
29+
3230
-- Author
3331
sum Author = Ivan | Jovan | Savo
3432
@@ -64,28 +62,17 @@ prod RichDocument = (Document RichContent)
6462
-- ## We need a list type
6563
sum List a = Nil | Cons a (List a)
6664
67-
-- ## We need a Char type that is either a letter, number or punctuation
68-
sum Char = Letter Letter | Number Number | Punctuation Punctuation
69-
70-
sum Letter = A | B | C
71-
72-
sum Number = Num0 | Num1 | Num2
73-
74-
sum Punctuation = Dot | Question
75-
7665
-- ## String
7766
prod String = (List Char)
7867
```
7968

8069
```shell
81-
$ nix run github:mlabs-haskell/lambda-buffers#lbf-to-haskell -- Document.lbf
70+
$ nix run github:mlabs-haskell/lambda-buffers#lbf-prelude-to-haskell -- Document.lbf
8271
$ find autogen/
8372
autogen/
84-
autogen/build.json
8573
autogen/LambdaBuffers
8674
autogen/LambdaBuffers/Document.hs
87-
$ ghc autogen/LambdaBuffers/Document.hs
88-
[1 of 1] Compiling LambdaBuffers.Document ( autogen/LambdaBuffers/Document.hs, autogen/LambdaBuffers/Document.o )
75+
autogen/build.json
8976
```
9077

9178
As we can see the `autogen` directory has been created that contains the generated Haskell modules.
@@ -94,83 +81,62 @@ Note the `autogen/build.json` file as it contains all the necessary Hackage depe
9481
The outputted Haskell module in `autogen/LambdaBuffers/Document.hs`:
9582

9683
```haskell
97-
module LambdaBuffers.Document
98-
( Author (..),
99-
Chapter (..),
100-
Char (..),
101-
Document (..),
102-
Gif (..),
103-
Image (..),
104-
Letter (..),
105-
List (..),
106-
Number (..),
107-
Punctuation (..),
108-
Reviewer (..),
109-
RichContent (..),
110-
RichDocument (..),
111-
String (..),
112-
)
113-
where
114-
84+
module LambdaBuffers.Document (Author(..)
85+
, Chapter(..)
86+
, Document(..)
87+
, Gif(..)
88+
, Image(..)
89+
, List(..)
90+
, Reviewer(..)
91+
, RichContent(..)
92+
, RichDocument(..)
93+
, String(..)) where
94+
95+
import qualified LambdaBuffers.Prelude
11596
import qualified Prelude
11697

117-
data Author = Author'Ivan | Author'Jovan | Author'Savo deriving (Prelude.Show)
118-
119-
data Chapter a = Chapter
120-
{ chapter'content :: a,
121-
chapter'subChapters :: List (Chapter a)
122-
}
123-
deriving (Prelude.Show)
12498

125-
data Char
126-
= Char'Letter Letter
127-
| Char'Number Number
128-
| Char'Punctuation Punctuation
129-
deriving (Prelude.Show)
99+
data Author = Author'Ivan | Author'Jovan | Author'Savo deriving Prelude.Show
130100

131-
data Document a = Document
132-
{ document'author :: Author,
133-
document'reviewers :: List Reviewer,
134-
document'content :: Chapter a
135-
}
136-
deriving (Prelude.Show)
101+
data Chapter a = Chapter { chapter'content :: a
102+
, chapter'subChapters :: List (Chapter a)} deriving Prelude.Show
137103

138-
data Gif = Gif'FunnyGif | Gif'InspiringGif deriving (Prelude.Show)
104+
data Document a = Document { document'author :: Author
105+
, document'reviewers :: List Reviewer
106+
, document'content :: Chapter a} deriving Prelude.Show
139107

140-
data Image = Image'FunnyImage | Image'BoringImage deriving (Prelude.Show)
108+
data Gif = Gif'FunnyGif | Gif'InspiringGif deriving Prelude.Show
141109

142-
data Letter = Letter'A | Letter'B | Letter'C deriving (Prelude.Show)
110+
data Image = Image'FunnyImage | Image'BoringImage deriving Prelude.Show
143111

144-
data List a = List'Nil | List'Cons a (List a) deriving (Prelude.Show)
112+
data List a = List'Nil | List'Cons a (List a) deriving Prelude.Show
145113

146-
data Number = Number'Num0 | Number'Num1 | Number'Num2 deriving (Prelude.Show)
114+
data Reviewer = Reviewer'Bob | Reviewer'Alice deriving Prelude.Show
147115

148-
data Punctuation
149-
= Punctuation'Dot
150-
| Punctuation'Question
151-
deriving (Prelude.Show)
116+
data RichContent = RichContent'Image Image String
117+
| RichContent'Gif Gif String
118+
| RichContent'Text String deriving Prelude.Show
152119

153-
data Reviewer = Reviewer'Bob | Reviewer'Alice deriving (Prelude.Show)
120+
newtype RichDocument = RichDocument (Document RichContent) deriving Prelude.Show
154121

155-
data RichContent
156-
= RichContent'Image Image String
157-
| RichContent'Gif Gif String
158-
| RichContent'Text String
159-
deriving (Prelude.Show)
122+
newtype String = String (List LambdaBuffers.Prelude.Char) deriving Prelude.Show
123+
```
160124

161-
newtype RichDocument = RichDocument (Document RichContent) deriving (Prelude.Show)
125+
We can compile the code with the following commands.
126+
Note the dev shell `dev-prelude-haskell` as it includes the `LambdaBuffers.Prelude` dependency.
162127

163-
newtype String = String (List Char) deriving (Prelude.Show)
128+
```shell
129+
$ nix develop github:mlabs-haskell/lambda-buffers#dev-prelude-haskell
130+
$ ghc autogen/LambdaBuffers/Document.hs
131+
[1 of 1] Compiling LambdaBuffers.Document ( autogen/LambdaBuffers/Document.hs, autogen/LambdaBuffers/Document.o )
164132
```
165133

166134
## Sum types
167135

168-
The types `Author`, `Reviewer`, `RichContent`, `Image`, `Gif`, `List`, `Char`,
169-
`Letter`, `Number` and `Punctuation` have been declared as sum types in the
170-
LamdaBuffers schema using the `sum` keyword.
136+
The types `Author`, `Reviewer`, `RichContent`, `Image`, `Gif`, and `List` have been declared as sum types in the LamdaBuffers schema using the `sum` keyword.
171137

172-
As we can see, notihing too surprising here, all the `sum` types become `data`
173-
in haskell.
138+
As we can see, nothing too surprising here, all the `sum` types become `data`
139+
in Haskell.
174140

175141
The only thing to notice is that the type name was prepended with `'` (single
176142
quote) to the defined constructor names as to make sure they are unique.

docs/purescript.md

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
Let's take a look at how LambdaBuffers modules map into Purescript modules and how
44
LambdaBuffers type definitions map into Purescript type definitions.
55

6-
Note that in this chapter we work with a 'pure' LambdaBuffers module, no
7-
`opaque`s or type clasess, to demonstrate how pure type definition mapping
8-
works.
9-
10-
We'll use the `lbf-to-purescript` CLI tool which is just a convenient wrapper over
6+
We'll use the `lbf-prelude-to-purescript` CLI tool which is just a convenient wrapper over
117
the raw `lbf` CLI. We can get this tool by either loading the LambdaBuffers Nix
128
environment that comes packaged with all the CLI tools:
139

1410
```shell
15-
$ nix develop github:mlabs-purescript/lambda-buffers#lb
16-
$ lb<tab>
17-
lbc lbf lbg lbg-purescript lbg-haskelll lbf-to-purescript lbf-to-haskell
11+
$ nix develop github:mlabs-haskell/lambda-buffers#lb
12+
$ lbf<tab>
13+
lbf lbf-plutus-to-purescript lbf-prelude-to-purescript
14+
lbf-plutus-to-haskell lbf-prelude-to-haskell
1815
```
1916

20-
Or we can simply just refer directly to the `lbf-to-purescript` CLI by `nix run
21-
github:mlabs-purescript/lambda-buffers#lbf-to-purescript`.
17+
Or we can simply just refer directly to the `lbf-prelude-to-purescript` CLI by `nix run
18+
github:mlabs-haskell/lambda-buffers#lbf-prelude-to-purescript`.
2219

2320
In this chapter, we're going to use the latter option.
2421

25-
Let's now use `lbf-to-purescript` to process the
22+
Let's now use `lbf-prelude-to-purescript` to process the
2623

2724
[Document.lbf](examples/Document.lbf) schema
2825

2926
```purescript
3027
module Document
3128
29+
-- We need the opaque Char type
30+
import Prelude (Char)
31+
3232
-- Author
3333
sum Author = Ivan | Jovan | Savo
3434
@@ -64,21 +64,12 @@ prod RichDocument = (Document RichContent)
6464
-- ## We need a list type
6565
sum List a = Nil | Cons a (List a)
6666
67-
-- ## We need a Char type that is either a letter, number or punctuation
68-
sum Char = Letter Letter | Number Number | Punctuation Punctuation
69-
70-
sum Letter = A | B | C
71-
72-
sum Number = Num0 | Num1 | Num2
73-
74-
sum Punctuation = Dot | Question
75-
7667
-- ## String
7768
prod String = (List Char)
7869
```
7970

8071
```shell
81-
$ nix run github:mlabs-purescript/lambda-buffers#lbf-to-purescript -- Document.lbf
72+
$ nix run github:mlabs-haskell/lambda-buffers#lbf-prelude-to-purescript -- Document.lbf
8273
$ find autogen/
8374
autogen/
8475
autogen/build.json
@@ -94,26 +85,23 @@ The outputted Purescript module in `autogen/LambdaBuffers/Document.hs`:
9485
```purescript
9586
module LambdaBuffers.Document (Author(..)
9687
, Chapter(..)
97-
, Char(..)
9888
, Document(..)
9989
, Gif(..)
10090
, Image(..)
101-
, Letter(..)
10291
, List(..)
103-
, Number(..)
104-
, Punctuation(..)
10592
, Reviewer(..)
10693
, RichContent(..)
10794
, RichDocument(..)
10895
, String(..)) where
10996
97+
import LambdaBuffers.Prelude as LambdaBuffers.Prelude
11098
import Data.Generic.Rep as Data.Generic.Rep
11199
import Data.Newtype as Data.Newtype
112100
import Data.Show as Data.Show
113101
import Data.Show.Generic as Data.Show.Generic
114102
115103
116-
data Author = Author'Ivan | Author'Jovan | Author'Savo
104+
data Author = Author'Ivan | Author'Jovan | Author'Savo
117105
derive instance Data.Generic.Rep.Generic Author _
118106
instance Data.Show.Show Author where
119107
show = Data.Show.Generic.genericShow
@@ -124,13 +112,6 @@ derive instance Data.Generic.Rep.Generic (Chapter a) _
124112
instance (Data.Show.Show a) => Data.Show.Show (Chapter a) where
125113
show = Data.Show.Generic.genericShow
126114
127-
data Char = Char'Letter Letter
128-
| Char'Number Number
129-
| Char'Punctuation Punctuation
130-
derive instance Data.Generic.Rep.Generic Char _
131-
instance Data.Show.Show Char where
132-
show = Data.Show.Generic.genericShow
133-
134115
newtype Document a = Document { author :: Author
135116
, reviewers :: List Reviewer
136117
, content :: Chapter a}
@@ -139,37 +120,22 @@ derive instance Data.Generic.Rep.Generic (Document a) _
139120
instance (Data.Show.Show a) => Data.Show.Show (Document a) where
140121
show = Data.Show.Generic.genericShow
141122
142-
data Gif = Gif'FunnyGif | Gif'InspiringGif
123+
data Gif = Gif'FunnyGif | Gif'InspiringGif
143124
derive instance Data.Generic.Rep.Generic Gif _
144125
instance Data.Show.Show Gif where
145126
show = Data.Show.Generic.genericShow
146127
147-
data Image = Image'FunnyImage | Image'BoringImage
128+
data Image = Image'FunnyImage | Image'BoringImage
148129
derive instance Data.Generic.Rep.Generic Image _
149130
instance Data.Show.Show Image where
150131
show = Data.Show.Generic.genericShow
151132
152-
data Letter = Letter'A | Letter'B | Letter'C
153-
derive instance Data.Generic.Rep.Generic Letter _
154-
instance Data.Show.Show Letter where
155-
show = Data.Show.Generic.genericShow
156-
157133
data List a = List'Nil | List'Cons a (List a)
158134
derive instance Data.Generic.Rep.Generic (List a) _
159135
instance (Data.Show.Show a) => Data.Show.Show (List a) where
160136
show = Data.Show.Generic.genericShow
161137
162-
data Number = Number'Num0 | Number'Num1 | Number'Num2
163-
derive instance Data.Generic.Rep.Generic Number _
164-
instance Data.Show.Show Number where
165-
show = Data.Show.Generic.genericShow
166-
167-
data Punctuation = Punctuation'Dot | Punctuation'Question
168-
derive instance Data.Generic.Rep.Generic Punctuation _
169-
instance Data.Show.Show Punctuation where
170-
show = Data.Show.Generic.genericShow
171-
172-
data Reviewer = Reviewer'Bob | Reviewer'Alice
138+
data Reviewer = Reviewer'Bob | Reviewer'Alice
173139
derive instance Data.Generic.Rep.Generic Reviewer _
174140
instance Data.Show.Show Reviewer where
175141
show = Data.Show.Generic.genericShow
@@ -187,7 +153,7 @@ derive instance Data.Generic.Rep.Generic RichDocument _
187153
instance Data.Show.Show RichDocument where
188154
show = Data.Show.Generic.genericShow
189155
190-
newtype String = String (List Char)
156+
newtype String = String (List LambdaBuffers.Prelude.Char)
191157
derive instance Data.Newtype.Newtype String _
192158
derive instance Data.Generic.Rep.Generic String _
193159
instance Data.Show.Show String where
@@ -196,11 +162,9 @@ instance Data.Show.Show String where
196162

197163
## Sum types
198164

199-
The types `Author`, `Reviewer`, `RichContent`, `Image`, `Gif`, `List`, `Char`,
200-
`Letter`, `Number` and `Punctuation` have been declared as sum types in the
201-
LamdaBuffers schema using the `sum` keyword.
165+
The types `Author`, `Reviewer`, `RichContent`, `Image`, `Gif`, and `List` have been declared as sum types in the LamdaBuffers schema using the `sum` keyword.
202166

203-
As we can see, notihing too surprising here, all the `sum` types become `data`
167+
As we can see, nothing too surprising here, all the `sum` types become `data`
204168
in Purescript.
205169

206170
The only thing to notice is that the type name was prepended with `'` (single

0 commit comments

Comments
 (0)