Worth noting that the ASM monad is “just” WriterT [Word8] ◦ StateT Loc which provides the functor instance, the applicative instance, the monad instance, the MonadWriter instance, the MonadState instance, the MonadFix instance, a MonadTrans instance if the author is interested, and even an Alternative/MonadPlus instance (e.g., the ability to have branching, non-deterministic computation in assembly if we adjoin a failing monad into the stack).
This is not a critique of anything in the post—it’s just a note that monads (and monad transformers) are really cool! If you know how to recognize monad decompositions like I just did then you can exploit it to read off whole lists of properties and implementations of functions.
Maybe it would be fruitful to re-post the best articles on lobste.rs on to hackernews -- for the comment/information gain....
There's nothing wrong with that...per se. But pop programming tends to be more flavor-of-the-month/bikeshedding oriented, so there's more to wade through. I'm worried lobste.rs will end up the same way.
"In a move that is sure to scare off both high-level and low-level programmers..." - quite.
* Expression evaluation: https://github.com/michaelmelanson/cminus-compiler/blob/mast...
* Statement compilation: https://github.com/michaelmelanson/cminus-compiler/blob/mast...
* Definition of the monad: https://github.com/michaelmelanson/cminus-compiler/blob/mast...
The 'compilation state' was wrapped up in a State monad which held a list of emitted instruction blocks, free registers, and so on. I didn't go as far as to wrap each of the instructions in their own functions to get an assembly-like DSL, but you can imagine defining functions like `add = emit $ ADD` for each instruction to get the same effect.