From bb924064b11aa36c245696db0419be8d7c9deb87 Mon Sep 17 00:00:00 2001 From: Ziyang Liu Date: Wed, 2 May 2018 16:27:36 -0700 Subject: [PATCH] Fix README in Person Example --- proto-lens-tutorial/coffee-order/README.md | 2 +- proto-lens-tutorial/person/README.md | 27 +++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/proto-lens-tutorial/coffee-order/README.md b/proto-lens-tutorial/coffee-order/README.md index a68f596f..f851f012 100644 --- a/proto-lens-tutorial/coffee-order/README.md +++ b/proto-lens-tutorial/coffee-order/README.md @@ -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 diff --git a/proto-lens-tutorial/person/README.md b/proto-lens-tutorial/person/README.md index a86cd28f..e01b4574 100644 --- a/proto-lens-tutorial/person/README.md +++ b/proto-lens-tutorial/person/README.md @@ -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: @@ -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 @@ -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: @@ -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 @@ -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 @@ -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) => @@ -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