Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix README in Person Example #190

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto-lens-tutorial/coffee-order/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Coffee Order Example

In this example we will go through a more complicated data structure compared to our [Person Example](https://github.com/FintanH/proto-lens/blob/docs/codelab/proto-lens-tutorial/person/README.md).
In this example we will go through a more complicated data structure compared to our [Person Example](../person/README.md).

## Table of Contents

Expand Down
27 changes: 11 additions & 16 deletions proto-lens-tutorial/person/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ I am going to use `stack` and `hpack` to set things up. So here we go:

The command to follow will create a basic Haskell directory structure for a [stack](https://docs.haskellstack.org/en/stable/README/) project. It will use `hpack` which is a way of defining your project in a `.yaml` file which generates a `.cabal` file upon `stack build`. After this we `cd` into the directory created.

`stack new person simple-hpack && cd person`
`stack --resolver lts-10.10 new person simple-hpack && cd person`

#### 2. Setup Proto

Now we have our top level project we are going to create a `proto` package inside:
`stack new proto simple-hpack`
`stack --resolver lts-10.10 new proto simple-hpack`

We will setup the stuff in this project first before coming back to `person`. In our `proto/src` directory we will remove `Main.hs` and replace it with a `person.proto` file with the following contents:

Expand All @@ -53,13 +53,16 @@ message Address {
}
```

Next we will edit the `package.yaml` file to add in the things we need:
Next we will edit the `package.yaml` file in `proto` to add in the things we need:

``` yaml
name: person-proto

custom-setup:
dependencies: base, Cabal, proto-lens-protoc
dependencies:
- base
- Cabal
- proto-lens-protoc

extra-source-files: src/**/*.proto

Expand All @@ -71,10 +74,11 @@ library:

exposed-modules:
- Proto.Person
- Proto.Person_Fields
```

This will autogenerate two modules `Proto.Person` where our records will be defined and `Proto.Person_Fields` where our field accessors will be defined.
This will autogenerate module `Proto.Person` where our records and their field accessors will be defined.

Then we delete `proto/proto.cabal`, since our package is named `person-proto`. `stack build` will generate `person-proto.cabal`.

The last thing we need to do here is edit `Setup.hs` to have:

Expand Down Expand Up @@ -133,7 +137,6 @@ Alright! We are going to test this puppy out! We will make a `Main.hs` in our ma
module Main where

import Proto.Person as P
import Proto.Person_Fields as P
import Data.Default
import Data.ProtoLens (showMessage)
import Lens.Micro
Expand Down Expand Up @@ -170,7 +173,7 @@ To find the ones we create you can run:

### Message and Lenses

When we build our protobuffers what is it we get? Code is autogenerated to give us two files `Person.hs` and `Person_Fields.hs` which contain our records and our field accessors respectively. This is roughly what they look like:
When we build our protobuffers what is it we get? Code is autogenerated to give us `Person.hs` which contains our records and our field accessors. This is roughly what it looks like:

``` haskell
-- Person.hs
Expand Down Expand Up @@ -212,13 +215,6 @@ data Person = Person
deriving (Prelude.Show, Prelude.Eq, Prelude.Ord)

-- same instances with different labels
```

``` haskell
-- Person_Fields.hs

module Proto.Person_Fields where
-- imports

addresses ::
forall f s t a b . (Lens.Labels.HasLens f s t "addresses" a b) =>
Expand Down Expand Up @@ -274,7 +270,6 @@ Using your favourite lens library we can create our proto data by doing the foll

``` haskell
import Proto.Person as P
import Proto.Person_Fields as P

fintan :: P.Person -- Signal the compiler what we are creating a Person
fintan = def & P.name .~ "Fintan" -- set the `name` of our person
Expand Down