On Tue, 2011-01-25 at 12:17 +0100, Gábor Lehel wrote: > On Tue, Jan 25, 2011 at 10:20 AM, Ketil Malde <[email protected]> wrote: > > Erik Hesselink <[email protected]> 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
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
