tags:

views:

411

answers:

3

In a recent blog post about a probability monad he'd written, Mark Dominus wrote, "So I feel like I've finally arrived, monadwise."

My first monadic program was an awkward solution to Problem 32 from Project Euler using parsec and the Maybe monad.

What were you working on when the light finally turned on for you? Provide at least a sketch of the code you wrote. Knowing what you know now, how would you improve it and why?

+3  A: 

When I realized that I could use monad for both parsing and interpreting, I was able to write my first mini-interpreter for a LUA-like dynamic programming language in F# on the first try. First-class continuations!, environment, mutable state, debugging - All just a big monad transformer stack.

Dario
+1  A: 

For me it was creating a variation on the QuickCheck "Gen" monad (which is used to create random values). I wanted to test something stateful, so I rewrote "Gen" as a monad transformer and stacked it up with a State monad. Somewhere in there the lightbulb went on.

Paul Johnson
+2  A: 

Some random computation code base on sampling. The type « m a » is a random variable of type « a » and « a -> m b » is a "random function". Random variables can very simply be handled this way. « replicateM n » is used to get independant samples from a same variable.

The do notation is fine as well : x <- y means x is a sample from the random variable y.

Martin