[Haskell-beginners] Ignoring the result of a monadic computation
earthnut at web.de
Fri Nov 19 17:31:28 EST 2010
On Nov 19, 2010, at 7:56, Tim Baumgartner wrote:
> while learning about monads, I had something like
> line <- getLine
> putStrLn line
> and I wondered if I could write it in one line, without naming of parameters.
> I finally came up with
> getLine >>= ignore something >>= putStrLn
> ignore :: Monad m => m a -> b -> m b
> ignore m a = m >> return a
> I'm satisfied with this solution but searching hoogle I didn't find a standard function for my ignore. Am I missing something?
I don't know if this is better, but you could also write
getLine >>= (something >>) . putStrLn
More information about the Beginners