Finding purity again
I'm getting back into Haskell since giving up on it around 2013 - of course due to work distractions, but mainly having the wrong expectation of what it would require from my brain to wrangle the fundamentals. At the time I found the syntax easy and beautiful, the paradigm of reductive programming very natural and the ability to describe and process data structures so elegant that I was absolutely smitten going through the beginner level tutorials and scratch programs.
You hit the wall pretty quickly however, as you start to learn Functors, Applicatives, Monoids and finally Monads. And although those seem ok in principle, my head was at it's limit trying to embed these new ideas. Very quickly though you discover that this is the tip of the iceberg, and in practise I ended up fighting and fighting - really just trying to get code compiling. If I couldn't get the basic stuff to compile, how the hell was I going to write real stuff?
There was something I did not understand, and it was fundamental. I had a hole in my brain, I was missing the building blocks, the intuition, the big picture. I gave up.
Enter Elm
All was not lost however - as I found solace in other languages such as Javascript and Scala where I was able to apply a bunch of those basic ideas I had learned from Haskell. I wrote better, more pure, less buggy and more concurrent code. Life was good again for many years, until one day I was working on a project using React with Redux on the front-end connected via Websockets to KStreams based stream processing on the backend (trying to build a fully event-driven architecture) I discovered Elm. It turns out that Elm really invented the Redux pattern - and had built an entirely new language and framwork around this idea nicknamed The Elm Architecture - or TEA for short. Elm clicked immediately for me, I think in part due to it looking familiar and waking up that old dormant Haskelley part of my mind - but it was also really easy to pickup, and so perfectly fit-for-purpose it was easy to understand and just get productive.
It didn't take long and I was whacking out web front-ends using ELM in no time. Small internal projects, hobby projects, anything that wasn't 'customer' or needed to be 'production' or 'maintainable' much. It turns out I had a few, and within a few months I had written thousands of lines and Elm and was really ontop of it. Elm is the future!
Exit Elm
I quickly discovered its limits though - and especially the difficulty in writing single-page-apps - i.e. the kind where you have one app, but many different 'pages' with many different 'model-update-view' type loops in it based upon the context, and typically some sort of 'router' that can move you between contexts. Elm really sucks for this - and I really tried hard to make it work - but fundamentally it's predicated on the single mega update loop idea, and so you quite quickly start to make a huge mess of your data structures as you need to munge everything together into a single model, for that single update call. Blegh. So Elm is awesome, but only for really simple web apps - and I had to reclassify it in my mind as a fun academic experiment, and no longer as a potential tool for real work.
Enter Purescript
Ahh this was the gateway drug for me. With Purescript I could write a very simple TEA type app, BUT I could also choose to combine many TEAs together to create a bigger single-page-app architecture. And Purescript looked basically the same as Elm from a syntax perspective so it was easy to switch quickly, and mostly could be made to fit into my mental model I had been building on. Purescript turns out to be MUCH more open and MUCH more general purpose - not limited to web application alone, but also able to be compiled to Javascript and executed by Nodejs. And although there was good Elm-like clones for Purescript, there are other potentially more interesting web models, such as Concur - which is closer to a webcomponents model, and so there is tons of choice.
Back to Haskell
Through writing more console based stuff you soon encounter Effect and Aff in the Purescript world - which are the very interesting containers for holding synchronous and asynchronous 'side-effects' respectively. These are actually really easy to grasp initially, but soon become difficult when you need to do stuff a little more complex than 'hello world'. Another area that knocked me off track was understanding how you mix code in each of these 'containers', and very soon Monad Transformers (aka mtl) get mentioned and once again you are back to square 1 of feeling like a noob, and all those old feelings from 2015 come rushing back. This time however, I'm ready for it. I am more well-rounded. I can see the value. I know the curve is steep. But I am committed.

Hopefully the above helps!
Article
{ slug: "finding-purity-again"
, originalUrl: Nothing
, title: "Finding purity again"
, date: constructDate 2021 2 16
, keywords: []
, cover: { alt: "code", caption: Nothing, src: "/images/covers/code_haskell_2.png" }
, summary: "No summary yet"
, author: { bio: "Towards an AI-first, hyper-scaled, functional reactive universe!", email: "tom@tomwells.org", name: "Tom Wells" }
, body:
[ FlowParagraph "I'm getting back into Haskell since giving up on it around 2013 - of course due to work distractions, but mainly having the wrong expectation of what it would require from my brain to wrangle the fundamentals. At the time I found the syntax easy and beautiful, the paradigm of reductive programming very natural and the ability to describe and process data structures so elegant that I was absolutely smitten going through the beginner level tutorials and scratch programs."
, FlowParagraph "You hit the wall pretty quickly however, as you start to learn Functors, Applicatives, Monoids and finally Monads. And although those seem ok in principle, my head was at it's limit trying to embed these new ideas. Very quickly though you discover that this is the tip of the iceberg, and in practise I ended up fighting and fighting - really just trying to get code compiling. If I couldn't get the basic stuff to compile, how the hell was I going to write real stuff?"
, FlowParagraph "There was something I did not understand, and it was fundamental. I had a hole in my brain, I was missing the building blocks, the intuition, the big picture. I gave up."
, FlowSection "Enter Elm"
, FlowParagraph "All was not lost however - as I found solace in other languages such as Javascript and Scala where I was able to apply a bunch of those basic ideas I had learned from Haskell. I wrote better, more pure, less buggy and more concurrent code. Life was good again for many years, until one day I was working on a project using React with Redux on the front-end connected via Websockets to KStreams based stream processing on the backend (trying to build a fully event-driven architecture) I discovered Elm. It turns out that Elm really invented the Redux pattern - and had built an entirely new language and framwork around this idea nicknamed The Elm Architecture - or TEA for short. Elm clicked immediately for me, I think in part due to it looking familiar and waking up that old dormant Haskelley part of my mind - but it was also really easy to pickup, and so perfectly fit-for-purpose it was easy to understand and just get productive."
, FlowParagraph "It didn't take long and I was whacking out web front-ends using ELM in no time. Small internal projects, hobby projects, anything that wasn't 'customer' or needed to be 'production' or 'maintainable' much. It turns out I had a few, and within a few months I had written thousands of lines and Elm and was really ontop of it. Elm is the future!"
, FlowSection "Exit Elm"
, FlowParagraph "I quickly discovered its limits though - and especially the difficulty in writing single-page-apps - i.e. the kind where you have one app, but many different 'pages' with many different 'model-update-view' type loops in it based upon the context, and typically some sort of 'router' that can move you between contexts. Elm really sucks for this - and I really tried hard to make it work - but fundamentally it's predicated on the single mega update loop idea, and so you quite quickly start to make a huge mess of your data structures as you need to munge everything together into a single model, for that single update call. Blegh. So Elm is awesome, but only for really simple web apps - and I had to reclassify it in my mind as a fun academic experiment, and no longer as a potential tool for real work."
, FlowSection "Enter Purescript"
, FlowParagraph "Ahh this was the gateway drug for me. With Purescript I could write a very simple TEA type app, BUT I could also choose to combine many TEAs together to create a bigger single-page-app architecture. And Purescript looked basically the same as Elm from a syntax perspective so it was easy to switch quickly, and mostly could be made to fit into my mental model I had been building on. Purescript turns out to be MUCH more open and MUCH more general purpose - not limited to web application alone, but also able to be compiled to Javascript and executed by Nodejs. And although there was good Elm-like clones for Purescript, there are other potentially more interesting web models, such as Concur - which is closer to a webcomponents model, and so there is tons of choice."
, FlowSection "Back to Haskell"
, FlowParagraph "Through writing more console based stuff you soon encounter Effect and Aff in the Purescript world - which are the very interesting containers for holding synchronous and asynchronous 'side-effects' respectively. These are actually really easy to grasp initially, but soon become difficult when you need to do stuff a little more complex than 'hello world'. Another area that knocked me off track was understanding how you mix code in each of these 'containers', and very soon Monad Transformers (aka mtl) get mentioned and once again you are back to square 1 of feeling like a noob, and all those old feelings from 2015 come rushing back. This time however, I'm ready for it. I am more well-rounded. I can see the value. I know the curve is steep. But I am committed."
, FlowImage { alt: "Practical Haskell Book", caption: (Just "Practical Haskell - A Real World Guide to Programming - By Alejandro Serrano Mena"), src: "/images/articles/just_a_monad/book.png" }
, FlowParagraph "Hopefully the above helps!"
]
}