[ Content | View menu ]

The Maybe Monad (In Ruby)

Mark Mzyk | February 15, 2008

At the tail end of last year I wrote a piece in which I waxed about a possible maybe operator. I haven’t looked into implementing anything like it because my time is limited and I don’t feel I (yet) have the technical expertise to do so. However, I was reminded of the concept again when I read about the maybe monad from Haskell being implemented in Ruby. Perhaps there’s a future out there for a maybe operator and maybe monads. That passing whimsy you have just might be a good idea after all.

Filed in: Languages,Programming.


  1. Comment by Tom R:

    I think the fundamental problem with the idea of a Maybe operator or similar construct is that you violate a precept of Computer Science – readability. Depending on where you look, the maintenance cost of computer science projects during their life cycle is upwards of 60-80% of total development effort – making straight forward code much better then short code. This is one of the reasons variable names have been getting longer and more descriptive in the .Net world of development. With the advent of intellisense – what does it matter if the function or variable is 15 characters long if you can type 4 letters and auto-complete. What’s important is that another programmer with less knowledge can follow your code.

    This reminds me of the obfuscation projects people do in C. Sure its possible to write code like that – but it doesn’t buy you a thing.

    February 19, 2008 @ 23:14
  2. Comment by James Norris:

    Your “maybe” operator sounds a lot like the SQL NULL value, especially in the sense that it allows a kind of three-valued logic. I’m not sure it’s a big win however.

    February 22, 2008 @ 17:32