Monads and Push

March 19, 2011
by Lee Spector (lspector)

I just watched a tutorial on monads (, and I was thinking about it in the context of the fact that Push instructions in some versions of Push (e.g. clojush) are all implemented as functions that take and return complete Push interpreter states. Very monad-like, I think. Mulling this a bit more I think there’s probably a nice way to use related ideas to provide a more elegant and uniform approach to several issues that have come up recently, including:

  • Protected state, as raised by Geoffrey Romer on the Push list and also addressed by Maarten Keijzer here.
  • The various uses to which the “auxiliary” stack has been put in some versions of Push, for problem inputs and other non-stack-like kinds of storage (e.g. tag bindings).
  • The handling of abnormal conditions (insufficient arguments, maybe semantic errors like division by zero).
  • More radical changes to the stack-based paradigm, e.g. Kyle Harrington’s experiments with a version of Push using bi-directional tapes instead of stacks.

I had previously mulled using the name Mush for a version of Push based around Maps (as in “hash maps”) rather than stacks, with stacks being just one kind of value to which something could map. In fact that’s what’s going on under the hood in clojush anyway. But maybe with some monad concepts mixed in the M in Mush could stand for “monad” instead (or in addition).

I haven’t thought this through to its logical conclusion; I’m sharing it in case anyone else would like to…

Leave a Reply

You must be logged in to post a comment.