Monads
Hannah Schroeter
uk1o@rz.uni-karlsruhe.de
Thu, 17 May 2001 18:18:13 +0200
Hello!
On Thu, May 17, 2001 at 11:57:45AM +0200, Rijk-Jan van Haaften wrote:
> >So what you are saying is that I actually don't need
> >Monads to perform the tasks Monads supports ?
> Indeed. However, not using the Monadic do syntax results in
> hardly-readible code.
I don't really think so. The operator precedences for >> and >>= are
quite okay, especially combined to the precedence of lambda binding.
How is
main =
getLine >>= \line ->
let number = read line in
let result = number + 42 in
print result
less readable than
main = do
line <- getLine
let number = read line
let result = number + 42
print result
?
Or
main =
putStr "Hello! What's your name?" >>
getLine >>= \name ->
putStrLn ("Hello, " ++ name ++ "!")
compared to
main = do
putStr "Hello! What's your name?"
name <- getLine
putStrLn ("Hello, " ++ name ++ "!")
> [...]
Yes, I use do syntax where appropriate (e.g. also for usual parser
monads), however, the operator syntax can be written quite readably
too.
Kind regards,
Hannah.