This article is inspired by Vitaly Bragilevsky’s talk on The clear path to Haskell complexities. This is not a Monad tutorial.
The Monad Madness
Ever since functional programming gaining momentum, people start writing monad tutorials. Monad becomes arguably the most famous buzzword in the field of functional programming, and there are memes on Monad.
I am neither proficient in Category Theory nor any programming languages for that matter but in the context of Haskell, I can’t agree more with Vitaly Bragilevsky’s advice that there is no understanding Monad problem, there are only definitions aka types, typeclasses, and laws. I highlighted…
The need arose when I was writing a full-stack web application with PureScript being the frontend and Haskell being the backend. While these two languages are largely similar, the fact that they are different implies that one cannot share the codes directly between them. For all data types defined in Haskell, I have to rewrite them in PureScript. This seems to be an automatable process so I decided to find a way to let the computer do the work for me! Let’s start with my preferred way of structuring data types in both languages.
Dealing with data types in PureScript…
In Haskell, we have three terminologies, term, type, and kind. Understanding their definitions are crucial to understanding Haskell as a practitioner.
Terms are runtime values, some examples are
Types are the type of terms, the type of
Int, the type of
Boolean, the type of
String and so on.
Kinds are the types of types. For example, the kind of type
Terms have type while types have kind.
Let’s start with the simplest data type which is defined in Haskell.
data Unit = Unit