Skip to content

thomashoneyman/purescript-halogen-realworld

Repository files navigation

Real World Halogen

RealWorld Frontend CI Maintainer: thomashoneyman

PureScript is a delightful pure functional language that offers pragmatic and powerful tools to help you design, build, and refactor reliable apps of any size. This repository demonstrates the principles I apply at work every day in more than 2,000 lines of thoroughly commented code.

I’m a developer at Awake Security (and previously at CitizenNet). Both companies have large production PureScript applications that have remained reliable, understandable, and maintainable as they scale.

This repository follows the RealWorld spec to implement a Medium clone called Conduit using Halogen. It’s large enough to demonstrate real world examples (CRUD, state management, scalable architecture, type classes, components, etc.) but not so large as to be overwhelming. There is also a Real World PureScript React project that demonstrates the same project using React bindings from PureScript.

The source code currently covers Halogen 7 with PureScript 0.15, but there are versions for versions going back to Halogen 4:

If you have found this repository and the guide useful, please consider becoming a sponsor!

Installation

First, clone the repository:

$ git clone https://github.com/thomashoneyman/purescript-halogen-realworld
Cloning into 'purescript-halogen-realworld'...
...
Resolving deltas: 100% (...), done.
$ cd purescript-halogen-realworld

You can enter a development shell with all non-JavaScript dependencies via Nix:

$ nix develop

Alternately, you can install purescript, spago, purs-tidy, purescript-psa, and the PureScript language server from NPM.

Next, install JavaScript dependencies:

$ npm install

Building and running

Next, build the project (this command will run spago build; see the package.json file to see all helper scripts for the project):

$ npm run build

You can bundle the JS for production:

$ npm run bundle

You can run a dev server to use Conduit:

$ npm run serve
...
 > Local:   http://127.0.0.1:8000/
 > Network: http://192.168.1.67:8000/

When you reload the application in the browser, esbuild will re-bundle the application using the latest compiled PureScript in the output directory. If you're using the PureScript language server, then this directory will be updated when you save files via incremental compilation.

Learning PureScript

This project is intended to give non-PureScript developers a taste of what a small application in the language looks like, and to give advanced beginners in PureScript a resource to feel comfortable building reliable applications of their own.

PureScript is a delightful language that becomes only more interesting and rewarding the more you use it and the larger your application becomes; if you haven’t yet tried it out, I encourage you to do so. Not convinced? Kris Jenkins has a lovely talk about PureScript which might change your mind.

Resources

The PureScript community is warm and helpful. If you would like some help getting started, please consider joining the official Discourse and official chat. You may also want to check out:

  1. The (warning: currently in rough draft form) handbook which explains the theory & principles at work in this application in-depth, which will be useful to help take you from advanced beginner to advanced intermediate in the language.
  2. The official Halogen guide, which will teach you how to use the Halogen framework to write components.
  3. PureScript by Example, which will teach you PureScript from scratch and was written by the language’s creator, Phil Freeman. While the official book has not been updated for the latest version of the compiler, this link is to an up-to-date fork of the book.
  4. Functional Programming Made Easier, a book by Charles Scalfani that teaches functional programming using PureScript.
  5. Jordan Martinez’s PureScript reference, which has a broad overview of dozens of topics in PureScript and functional programming.

Contributing

PRs are welcome! Any functional changes will need to remain compliant with the RealWorld spec, and I may re-word documentation changes to fit with the voice used throughout the repository.