Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Connecting a Haskell backend to a Purescript frontend using purescript-bridge - #46

Merged
javcasas merged 33 commits into
tutorialsfrom
connecting_haskell_backend_to_purescript_frontend
Jul 13, 2017
Merged

Connecting a Haskell backend to a Purescript frontend using purescript-bridge#46
javcasas merged 33 commits into
tutorialsfrom
connecting_haskell_backend_to_purescript_frontend

Conversation

@javcasas

Copy link
Copy Markdown
Contributor

No description provided.

@javcasas
javcasas force-pushed the connecting_haskell_backend_to_purescript_frontend branch 7 times, most recently from e357098 to 00be448 Compare May 19, 2017 14:31
@javcasas
javcasas force-pushed the connecting_haskell_backend_to_purescript_frontend branch from 00be448 to 355c48b Compare May 19, 2017 14:32
@javcasas
javcasas force-pushed the connecting_haskell_backend_to_purescript_frontend branch from c5fb021 to a32c875 Compare May 19, 2017 14:40
@javcasas
javcasas force-pushed the connecting_haskell_backend_to_purescript_frontend branch from e0694c7 to 9288925 Compare May 19, 2017 14:57
@javcasas
javcasas requested a review from nebtrx June 23, 2017 14:34

@sestrella sestrella left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas I left some comments. I'm going to continue reading your blog post in few hours. So far looks good. Great job!

@@ -0,0 +1,339 @@
---
title: Connecting a Haskell Backend to a Purescript Frontend

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas According to the official page, the name is written as PureScript.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

---
# Connecting a Haskell Backend to a Purescript Frontend
## Introduction
At Stackbuilders we are working on a full-stack app with CollegeVine https://www.collegevine.com/ using functional languages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas Could you replace Stackbuilders with Stack Builders please?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to also link the name to the web page like Stack Builders and CollegeVine wydt?

@javcasas javcasas Jun 23, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm getting the hang of linking in Markdown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of links placed.

# Connecting a Haskell Backend to a Purescript Frontend
## Introduction
At Stackbuilders we are working on a full-stack app with CollegeVine https://www.collegevine.com/ using functional languages.
We have a Haskell backend, based on Servant, that manipulates the database and offers some endpoints to a Purescript frontend,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas Could we remove some commas here in order to make reading more fluid? What about:

We have a backend written in Servant that manipulates the database and offers some endpoints to a PureScript frontend ...

Also, I think would be nice to include some links to some of the packages you are referencing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed commas, preparing to link stuff

---
# Connecting a Haskell Backend to a Purescript Frontend
## Introduction
At Stackbuilders we are working on a full-stack app with CollegeVine https://www.collegevine.com/ using functional languages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas I noticed you capitalize Functional some paragraphs below. Maybe we want to keep some consistency. What about replacing functional languages with Functional languages or Functional Languages perhaps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to Functional Languages, and in general Functional <capitalized word>


### Motivation
The problem is that we have two different codebases: one in Haskell and the other in Purescript.
The syntax is almost the same, but that small difference means we can't directly share files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas I'm not sure what you are referring to on this statement but that small difference. I understand it has to be with Haskell and PureScript but maybe we need to be more explicit about what specific difference we are talking about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples of differences provided.


### The next best thing
Well, if we can't use the same files, we have to look for something not that far from that ideal world.
If we can somehow automatically generate the Purescript code from the Haskell code,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas what about:

If we can somehow automatically generate PureScript types from Haskell, we could prevent type mismatches.

You may notice that I replace code with types. That's because purescript-bridge description on Hackage mentioned:

Generate PureScript data types from Haskell data types.

So maybe we need to clarify that we are going to generate only types. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from code to types.


### `purescript-bridge` to the rescue
Turns out this idea is not new, and Robert Klotzner has already done it for us, which is quite nice.
From the docs, purescript-bridge tells us it will write Purescript code from Haskell types,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas same here maybe we need to clarify that we are only going to generate types:

PureScript types from Haskell types

instead of:

Purescript code from Haskell types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to types again.

But let's not talk about limitations. Instead, let's talk about awesomeness. But, before that, let's review the general architecture.

## Simple WebApp
Our app will be split in two parts:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas split into two parts instead of split in two parts maybe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

## Simple WebApp
Our app will be split in two parts:
* A Haskell backend that talks to the database, coordinates people, sends emails and all that awesome stuff backends do.
* A Purescript frontend that compiles to Javascript and runs on the browser;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas please replace Javascript with JavaScript.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed across the document.

* A Purescript frontend that compiles to Javascript and runs on the browser;
showing, in marvellous details using React, all the data that fetches from the backend.

The two parts have to talk to eachother in order to have something useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas each other instead of eachother perhaps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@javcasas

Copy link
Copy Markdown
Contributor Author

Another question: the code is in my Github domain (github.com/javcasas). Shall I move it to StackBuilders? How do we do that?

@nebtrx nebtrx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Nice job @javcasas !

---
# Connecting a Haskell Backend to a PureScript Frontend
## Introduction
At [Stack Builders](https://www.stackbuilders.com) we are working on a full-stack app with [CollegeVine](https://www.collegevine.com/) using Functional Languages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to disclose the company's name?.Just checking

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mohan told Cynthia he was interested in the tutorial. I'll send the draft to him so he can decide if he wants his company to be included or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for confirmation from the client in order to see if he wants us to name the company.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mohan approved the tutorial:

Looks great! I wouldn't say that I was worried you were going to say something negative,
but more that I wanted to see the tone and language of the article since we don't really talk about our engineering publicly. Overall we are happy to be part of this great discovery! :)

we could prevent the problem of type difference. We would effectively extend the typesystem from the backend to the frontend.

### `purescript-bridge` to the rescue
Turns out this idea is not new, and Robert Klotzner has already done it for us, which is quite nice.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can yo reference Robert Klotzner with a link to his personal website of Twitter account?

@nebtrx

nebtrx commented Jun 26, 2017

Copy link
Copy Markdown
Contributor

BTW, you should add the code inside a code directory. Just like this

@nebtrx nebtrx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm going to request changes in order to remember you adding the code :)

@sestrella sestrella left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas I just leave some minor comments. Other than that LGTM. Great job!


### `purescript-bridge` to the rescue
Turns out this idea is not new, and Robert Klotzner has already done it for us, which is quite nice.
From the docs, [`purescript-bridge`](https://hackage.haskell.org/package/purescript-bridge) tells us it will write PureScript types from Haskell types,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas adding quotes to a link seems like a redundant emphasize. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing quotes.

bFoos :: [Foo]
} deriving (Generic)
```
Whereas if I want to get a Generic instance for my `Blah` type, in PureScript I have to do:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javcasas Usually, tutorials are written using third person form. What do you think about rewriting this paragraph as follows:

Whereas, if we want to get a Generic instance for `Blah` type, in PureScript we have to do:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it.

@@ -0,0 +1,66 @@
# This file was automatically generated by 'stack init'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you remove all this boilerplate, please? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

javcasas added 3 commits July 13, 2017 15:46
…sh://github.com/stackbuilders/tutorials into connecting_haskell_backend_to_purescript_frontend
@javcasas

Copy link
Copy Markdown
Contributor Author

Ok, I'm going to merge this to see how well does it look on Staging.

@javcasas
javcasas merged commit d53cd4c into tutorials Jul 13, 2017
@javcasas
javcasas deleted the connecting_haskell_backend_to_purescript_frontend branch July 13, 2017 22:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants