Thiago Negri | 27 Sep 21:51 2013
Picon

Proposal: new function for lifting

Everybody is claiming that using lift is a bad thing.
So, I come to remedy this problem.

Stop lifting, start using shinny operators like this one:

    (^$) :: Monad m => m a -> (a -> b -> c) -> m b -> m c
    (^$) = flip liftM2

Then you can do wonderful stuff and you will never read the four-letter word in your code again:

    \> Just 42 ^$(+)$ Nothing
    Nothing
    \> Just 10 ^$(+)$ Just 20
    Just 30
    \> let add = (+)
    \> Just 30 ^$ add $ Just 12
    Just 42

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Wvv | 27 Sep 22:12 2013
Picon

Re: Proposal: new function for lifting

Which "lift"?
This one?

class MonadTrans t where
    lift :: Monad m => m a -> t m a

--
View this message in context: http://haskell.1045720.n5.nabble.com/Proposal-new-function-for-lifting-tp5737189p5737196.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
Nick Vanderweit | 27 Sep 22:21 2013
Picon

Re: Proposal: new function for lifting

Sorry for sending this twice; I didn't reply to the list initially.

I thought people [1] were generally talking about lift from
Control.Monad.Trans:

class MonadTrans t where
    lift :: Monad m => m a -> t m a

The idea being that lifting through a monad stack feels tedious. The
proposed solution is to use instances to do the lifting for you, like in
mtl. So we've got instances like:

MonadState s m => MonadState s (ReaderT r m)

Which let you automatically lift get/put/modify up a stack, without doing
any work.

This is different from liftM*, which are about applying a pure function
to monadic arguments. This can be done quite nicely with (<$>) and (<*>)
from Data.Functor and Control.Applicative, respectively. Your first
example can be written:

(+) <$> (Just 42) <*> Nothing

Nick

[1]
http://blog.ezyang.com/2013/09/if-youre-using-lift-youre-doing-it-wrong-probably/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Marc Ziegert | 29 Sep 02:13 2013
Picon
Picon

Re: Proposal: new function for lifting

this is a funny trick, and it looks saner than the more general <$> <*> combinators.
i see many situations where i could use that to lift my own combinators,
or to replace the backticks (``) to lift the infix function.

thx
- marc

Gesendet: Freitag, 27. September 2013 um 21:51 Uhr
Von: "Thiago Negri" <evohunz <at> gmail.com>
An: Haskell-Cafe <haskell-cafe <at> haskell.org>
Betreff: [Haskell-cafe] Proposal: new function for lifting

Everybody is claiming that using lift is a bad thing.
So, I come to remedy this problem.
 

Stop lifting, start using shinny operators like this one:
 

    (^$) :: Monad m => m a -> (a -> b -> c) -> m b -> m c
    (^$) = flip liftM2
 
Then you can do wonderful stuff and you will never read the four-letter word in your code again:
 
    \> Just 42 ^$(+)$ Nothing
    Nothing
    \> Just 10 ^$(+)$ Just 20
    Just 30
    \> let add = (+)
    \> Just 30 ^$ add $ Just 12
    Just 42
 
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Bas van Dijk | 29 Sep 11:53 2013
Picon

Re: Proposal: new function for lifting

On 27 September 2013 21:51, Thiago Negri <evohunz <at> gmail.com> wrote:
> Stop lifting, start using shinny operators like this one:
>
>     (^$) :: Monad m => m a -> (a -> b -> c) -> m b -> m c
>     (^$) = flip liftM2

Note that something like this is already provided by the
InfixApplicative library:

http://hackage.haskell.org/package/InfixApplicative

Gmane