Questions tagged [monad-transformers]

Monad transformers are an abstraction for combining monads. This allows you to compose different computational effects, building up precisely controlled computational environments.

Monad transformers were introduced by Mark P. Jones in his 1993 paper, http://web.cecs.pdx.edu/~mpj/pubs/composing.html

756 questions
126
votes
7 answers

Applicatives compose, monads don't

Applicatives compose, monads don't. What does the above statement mean? And when is one preferable to other?
96
votes
3 answers

mtl, transformers, monads-fd, monadLib, and the paradox of choice

Hackage has several packages for monad transformers: mtl: Monad transformer library transformers: Concrete functor and monad transformers monads-fd: Monad classes, using functional dependencies monads-tf: Monad classes, using type…
yairchu
  • 23,680
  • 7
  • 69
  • 109
87
votes
3 answers

Haskell: lift vs liftIO

In what situations should liftIO be used? When I'm using ErrorT String IO, the lift function works to lift IO actions into ErrorT, so liftIO seems superfluous.
Lachlan
  • 3,744
  • 2
  • 26
  • 29
72
votes
6 answers

The Pause monad

Monads can do many amazing, crazy things. They can create variables which hold a superposition of values. They can allow you to access data from the future before you compute it. They can allow you to write destructive updates, but not really. And…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
70
votes
4 answers

Is there a monad that doesn't have a corresponding monad transformer (except IO)?

So far, every monad (that can be represented as a data type) that I have encountered had a corresponding monad transformer, or could have one. Is there such a monad that can't have one? Or do all monads have a corresponding transformer? By a…
Petr
  • 62,528
  • 13
  • 153
  • 317
58
votes
1 answer

Why is there no IO transformer in Haskell?

Every other monad comes with a transformer version, and from what I know the idea of a transformer is a generic extension of monads. Following how the other transformers are build, IOT would be something like newtype IOT m a = IOT { runIOT :: m (IO…
David
  • 8,275
  • 5
  • 26
  • 36
56
votes
3 answers

Simplest non-trivial monad transformer example for "dummies", IO+Maybe

Could someone give a super simple (few lines) monad transformer example, which is non-trivial (i.e. not using the Identity monad - that I understand). For example, how would someone create a monad that does IO and can handle failure (Maybe)? What…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
55
votes
6 answers

Has anyone ever encountered a Monad Transformer in the wild?

In my area of business - back office IT for a financial institution - it is very common for a software component to carry a global configuration around, to log its progress, to have some kind of error handling / computation short circuit... Things…
martingw
  • 4,153
  • 3
  • 21
  • 26
53
votes
2 answers

Avoiding lift with monad transformers

I have a problem to which a stack of monad transformers (or even one monad transformer) over IO. Everything is good, except that using lift before every action is terribly annoying! I suspect there is really nothing to do about that, but I thought…
aelguindy
  • 3,703
  • 24
  • 31
53
votes
1 answer

Monad Transformers vs Passing parameters to functions

I am new to Haskell but understand how Monad Transformers can be used. Yet, I still have difficulties grabbing their claimed advantage over passing parameters to function calls. Based on the wiki Monad Transformers Explained, we basically have a…
Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101
36
votes
2 answers

Goto in Haskell: Can anyone explain this seemingly insane effect of continuation monad usage?

From this thread (Control.Monad.Cont fun, 2005), Tomasz Zielonka introduced a function (commented in a clear and nice manner by Thomas Jäger). Tomasz takes the argument (a function) of a callCC body and returns it for later usage with the following…
makelc
  • 867
  • 8
  • 10
32
votes
3 answers

What are Haskell's monad transformers in categorical terms?

As a math student, the first thing I did when I learned about monads in Haskell was check that they really were monads in the sense I knew about. But then I learned about monad transformers and those don't quite seem to be something studied in…
31
votes
1 answer

Monad transformers libraries - which one to use?

There are many different monad transformers libraries on Hackage. A few seem to get more attention than the others. To name a few: mtl (current version depending on transformers for some reason), transformers, monadLib, monads-tf, mtlx,…
Tener
  • 5,280
  • 4
  • 25
  • 44
30
votes
2 answers

What is the RWS Monad and when is it used

I ran across the RWS Monad and its MonadTransformer while looking up something in the mtl library. There is no real documentation there, and I was wondering what this is and where it gets used. I've gotten as far as finding that RWS is an acronym…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
29
votes
1 answer

How to inject a Maybe value into MaybeT

Say I have some foo :: Maybe Int and I want to bind it for example with bar :: Int -> MaybeT (Writer String) Int, what would be the idiomatic way to do that? I could define my own liftMaybe function, and then use that, like: let liftMaybe = maybe…
user1078763
  • 728
  • 5
  • 15
1
2 3
50 51