[Haskell-cafe] Proposal: Applicative => Monad: Call for consensus

Maciej Piechotka uzytkownik2 at gmail.com
Tue Jan 25 21:38:42 CET 2011


On Tue, 2011-01-25 at 12:17 +0100, Gábor Lehel wrote:
> On Tue, Jan 25, 2011 at 10:20 AM, Ketil Malde <ketil at malde.org> wrote:
> > Erik Hesselink <hesselink at gmail.com> writes:
> >
> >>>> importing Control.Applicative
> >
> >>> main = print =<< liftM2 (+) readLn (return 3)
> >>> [...] line noise
> >
> >> Why not just:
> >>
> >> main = print . (+3) =<< readLn
> >
> > Or using applicative:
> >
> >  print =<< (+3) <$> readLn
> >
> > ?
> >
> > (Which separates the printing from the addition.)
> >
> > -k
> 
> IMHO, all these proposed solutions just serve to further illustrate
> the problem. :-)
> 

Even SHE?

main = (| print (| readLn + ~5 |) @|)

int main () {
	print ("%d\n", readLn () + 5);
}

Looks rather similar (except noise of both languages).

> Personally I don't mind having to use explicit combinators to interact
> with monadic values -- forces me to think things through, and all that
> -- but it's true that having automatic lifting would be convenient,
> and look less syntaxy. 

class Debug m where
    debug :: Show a => m a -> m a

instance Debug (Writer [String]) where
    debug x = tell (show x)

instance Debug IO where
    debug = print

instance (Show w, Show a) => Show (Writer w) where
    -- Yes I'm using old mtl to illustrate the problem
    show (Writer (a, w)) = "Writer (" ++ show a ++ ", " ++ show w ++ ")"

main = debug (return (return ())) *> return ()

What does it do?

- In case of no lifting it prints "Writer ((), [])"
- In case of lifting it may mean "debug <$> return (return ())" which
would not print anything

Regards

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110125/416947cb/attachment.pgp>


More information about the Haskell-Cafe mailing list