purescript / purescript-transformers

Monad and comonad transformers
BSD 3-Clause "New" or "Revised" License
69 stars 44 forks source link

Add lift2, lift3, lift4 .... functions? #108

Closed georgevarghese185 closed 6 years ago

georgevarghese185 commented 6 years ago

Would it make sense to add some helper functions to do multiple lifts in a row? I find myself doing 2 or 3 lifts in quite a few places where I have stacks of Monad Transformers and it would be nice if some already defined liftn functions existed...

hdgarrood commented 6 years ago

Like this?

lift2 :: forall m a t t'.
  MonadTrans t =>
  MonadTrans t' =>
  Monad m =>
  Monad (t m) =>
  m a ->
  t' (t m) a
lift2 = lift <<< lift

Might be worth using a slightly different name to avoid clashing with the Applicative liftn functions.

georgevarghese185 commented 6 years ago

Oh that's true. What about liftT2, liftT3 ? But now it seems different from lift which doesn't have a T in it.

hdgarrood commented 6 years ago

Yes, that's a good point. Maybe it would be best to call them lift2, lift3, etc, and let people import Control.Monad.Trans.Class qualified and use them like Trans.lift2 or something.

I don't have an opinion for or against adding these functions, though.

garyb commented 6 years ago

I would say that the need for these functions is probably fairly uncommon, as the MonadState, etc. classes will lift through as many layers as necessary.

hdgarrood commented 6 years ago

Good point. Shall we close this, then?