Drawing Fractals with PureScript

Recently, for no good reason, I added an easter egg to my personal website. I love fractals and decided to add a visualization of the dragon curve. Here were the requirements: Every 10 seconds, a new iteration of the dragon curve would be drawn. If the user clicked anywhere within the drawing area, a new iteration would be drawn and the 10 second clock would be reset. After the 10th iteration is drawn, the drawing should be cleared and the process should restart. I decided to use SVG to draw the lines of the fractal. Initially, I built a solution in Elm. However, I was missing the flexibility I’d experienced with my previous back end work in PureScript and wanted to explore using it on the front end. This post walks through the process of rebuilding the solution in PureScript. ...

June 3, 2020 · Drew Olson

Building a Slack Bot in PureScript

I recently open sourced my first large PureScript project. It’s a slack bot that allows searching for cards from the Epic Card Game. In this post, I’ll discuss the process of writing the application, what went well and what went poorly. An Overview of the Slack Bot I was excited about building this project in PureScript because it was complicated enough to be interesting but not so complicated as to be overwhelming. The key requirements for the bot were: ...

January 31, 2020 · Drew Olson

PureScript Async FFI

I recently posted about using Aff for asynchronous effects in PureScript. In this follow-up post, I’m going to discuss using JavaScript FFI in conjuction with Aff. Aff and FFI PureScript gives us very nice FFI utilities to call JavaScript code. Aff provides a function called fromEffectFnAff that lets us turn asynchronous JavaScript behavior into an Aff in our PureScript code. Let’s create an example that reads a file from the file system using FFI. We’ll pass our foreign function a String and expect to get back an Aff String of the contents of the file. ...

January 4, 2020 · Drew Olson

Asynchronous PureScript

One of my favorite features of PureScript is its ability to work with asynchronous effects. While learning the language, I struggled to find any beginner material that introduced the relevant topics and included small examples. This post hopes to fill that gap. Getting Started with Aff PureScript’s built-in type for effects is called Effect. However, this type represents synchronous effects. This means if we want expose asynchronous APIs to our users using Effect, we’re stuck with the callback-style. Here’s a contrived example that “slowly” adds two numbers together using Effects: ...

December 17, 2019 · Drew Olson

Laziness in PureScript

I’ve been learning PureScript for the past few months and really enjoying it. PureScript is a Haskell dervied language that compiles to JavaScript. You can target node for the backend or the browser for frontend code. One of my favorite features of PureScript is its fantastic interop with JavaScript. This makes the language very pragmatic – though it has a large ecosystem of native packages, anything that’s missing can easily be handled with an existing npm package and interop. PureScript made a big departure from Haskell in order to make this interop more convenient. While Haskell is a lazy language by default, PureScript is strict. ...

June 19, 2019 · Drew Olson