Collection of links to monad implementations in various languages.

Due to recent discussions here on LtU and on the Haskell mailing lists I've compiled a list of links to implementations of monads in various languages. If you know of any that aren't listed here, please submit them in a comment.

A longer article with side by side comparisons of the implementations would be interesting, and may help students understand monads by separating them from any one syntax or implementation.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

my c++ experiments ...

this is a translation of the sheep example in the monad tutorial to c++.
features a poor try to use c++ template spezialization as substitute for type-classes ...

hope this qualifies ;)

Monadic Programming in Scheme

Don't forget Oleg's Monadic Programming in Scheme.



Monad shell?

Don't know if this has anything to do with monads but looks interesting. (I confess, all I did was google "monad").

Windows Monad Shell

probably off topic, but this

probably off topic, but this is an interesting video.

Skip to track 5 for the monad conversation and I recommend using the transcript since it is hard to read the code samples in the video. You can cue the video from the transcript which is pretty cool.

in the realm of the heroic

dimitre novatchev has a monad in xslt - not released yet

Monads in Miranda

I thought i'd add a miranda implementation to the discussion. The transliteration is not a 100% percent exact, in that the ADT "maybe" is acessible to the rest of the program and because of that can always inspect the innards of the maybemonad. This hiding can be achieved by placing a '%export maybeMonad' compiler directive at the top of the script. This hides all definitions except those explicitly exported but obfuscates the main point which is the monad type. This discussion is a good companion to the implementation (as I used it as a base).

here for a overview of Turner's miranda language.

  maybeMonad *
  || make an instance of the monad container 
  return     :: * -> maybeMonad *  
  || 'flatten' some unneeded layers of packing (just needed in bind?)
  join       :: maybeMonad (maybeMonad *) -> maybeMonad *
  || apply some operation on the secret value of the monadic container 
  mapfunctor :: (* -> **) -> (maybeMonad *) -> (maybeMonad **)
  || apply some operation on monads, on this monad's value 
  bind       :: (maybeMonad *) -> (* -> (maybeMonad **)) -> (maybeMonad **)
maybe *      ::= Just *
               | Nothing

maybeMonad * == maybe *

|| return 'Just' a :)
return a = (Just a)

|| flatten a nesting of maybe's (N.B. typing ensures a = (Just b))
join (Just a) = a

|| apply an functor to our value
mapfunctor f (Just a)  = Just (f a)
mapfunctor f (Nothing) = Nothing

|| combine the this computation with another
bind a f = join (mapfunctor f a)

An example use is as follows:

foo n = return (10*n)

main  = bind (return 1) foo

which reduces to: (Just 10)

ps. Many thanks to Ehud for keeping this site running, I really enjoy it!

Maybe's left concrete in Hask

Maybe's left concrete in Haskell anyway - it doesn't turn out to be too big an issue, as in practice the alternative would be a runMaybe function that did the pattern-matching for you anyway.

Ok, since, in haskell, monads

Ok, since, in haskell, monads are used to seperate dirty computation from the pure ones, I assumed that it was a property of monads that there shouldn't be any unwrap function so contaminated values could never disrupt the pureness of the rest, but upon further investigation this doesn't seem to be the case for monads in general (which actually makes a lot of sense, since it is just a strategy for combining computations of some type, why shouldn't you be able to get the resulting value).

Thank you for clearing that up for me.

Yep, any monad implemented in

Yep, any monad implemented in Haskell without using the IO monad or similar yields "externally pure" computations. Similarly, you can build monads that yield computations in other monads when you 'run' their computations - a bit like building a virtual machine on top of a real one.


(Stumbled over this when browsing old #haskell irc logs)
Monadic parsing in Tcl
Maybe and Error

Need work

Those pages are a bit of a mess and quite confused in places. I've been planning on rewriting them, but that probably won't happen for a week or two.



Take a look at this. (And the LINQ is a well designed Monadic environment too.)