6

As the title says, I'm looking for a program that uses monad-transformers in combination with a large stack of Monads.

Does anybody know a real-world example?

nudded
  • 63
  • 3
  • The more the better. But >3 is a good start. – nudded Oct 12 '12 at 09:21
  • I'd note that a large monad stack is not necessarily a good thing. In a lot of code (including code by good Haskell programmers) you'll see people roll their own Monad rather than use a transformer stack. – Chris Taylor Oct 12 '12 at 09:26
  • The point is to have composability of components (implemented as monadic computations) using transformers. – nudded Oct 12 '12 at 10:17
  • 1
    Yeah, I know what the point is - I'm saying that often, a large monad stack is just an inconvenience. For example, see [this answer](http://stackoverflow.com/a/2760709/546084) by Norman Ramsey, where he says that "the GHC developers generally avoid monad transformers." The GHC developers are as close to expert Haskell programmers as you can get. If they don't user monad transformers, I would certainly think twice before using one. – Chris Taylor Oct 12 '12 at 16:10

2 Answers2

8

One good example is Haskeline - its internal InputCmdT type is a monad transformer stack of depth 6 (see here):

type InputCmdT m = StateT Layout (UndoT (StateT HistLog (ReaderT (IORef KillRing)
                (ReaderT Prefs (ReaderT (Settings m) m)))))

Which can actually have curious effects, such as blowing one type signature in System.Console.Haskeline.Emacs up to over 20.000 lines for at least one GHC version...

Peter Wortmann
  • 2,272
  • 14
  • 14
5

I don't know if this counts as "real world", but in my extension of the tutorial Write Yourself a Scheme in 48 Hours I implemented an interpreter for a programming language that uses the following stack:

type Eval a = ReaderT Environment (ErrorT LispError IO a)

and I begun adding continuations to the language by defining

type EvalCont r a = ContT r (ReaderT Environment (ErrorT LispError IO a))

I never finished implementing continuations, but you can see how far I got by checking it out on Github.

Chris Taylor
  • 46,912
  • 15
  • 110
  • 154