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.

By shapr at 2005年11月25日 14:20 | Software Engineering | other blogs | 39163 reads

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 ;)

By slom at Fri, 2005年11月25日 15:57 | login or register to post comments

Monadic Programming in Scheme

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

By Anton van Straaten at Fri, 2005年11月25日 16:17 | login or register to post comments

FC++

By Jim Apple at Fri, 2005年11月25日 16:42 | login or register to post comments

Scala

By Kooch at Fri, 2005年11月25日 17:57 | login or register to post comments

Interpreter with continuation

By ski at Wed, 2005年12月07日 10:25 | login or register to post comments

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

By Kooch at Fri, 2005年11月25日 18:04 | login or register to post comments

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.

By daryabeygi at Sun, 2005年11月27日 00:17 | login or register to post comments

in the realm of the heroic

dimitre novatchev has a monad in xslt - not released yet

By pantagruel at Fri, 2005年11月25日 20:56 | login or register to post comments

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).

See
here for a overview of Turner's miranda language.

abstype
 maybeMonad *
with 
 || 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!

By Jillis ter Hove at Mon, 2005年11月28日 18:32 | login or register to post comments

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.

By Philippa Cowderoy at Tue, 2005年11月29日 10:05 | login or register to post comments

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.

By Jillis ter Hove at Tue, 2005年11月29日 15:32 | login or register to post comments

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.

By Philippa Cowderoy at Tue, 2005年11月29日 17:25 | login or register to post comments

Tcl

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

By ski at Wed, 2005年11月30日 10:44 | login or register to post comments

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.

By Neil Madden at Thu, 2005年12月01日 02:52 | login or register to post comments

Slate

By ski at Tue, 2005年12月06日 12:14 | login or register to post comments

C#

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

By kaveh.shahbazian at Sun, 2007年12月09日 19:59 | login or register to post comments

AltStyle によって変換されたページ (->オリジナル) /