Do notation considered harmful
Haskell's do notation is popular and ubiquitous. However we shall not ignore that there are several problems. Here we like to shed some light on aspects you may not have thought about, so far.
This is wanted in order to simplify writing imperative style code fragments. The downsides are
- that, since notation is used almost everywhere, wheredotakes place, newcomers quickly believe that theIOnotation is necessary for doingdo,IO
- and that newcomers think, that is somehow special and non-functional, in contrast to the advertisement for Haskell being purely functional.IO
These misunderstandings let people write clumsy code like
do putStrLn "text"
do text <- getLine return text
do text <- readFile "foo" writeFile "bar" text
readFile "foo" >>= writeFile "bar"
1.2 Library design
2 See also
- Paul Hudak in Haskell-Cafe: A regressive view of support for imperative programming in Haskell
- Data.Syntaxfree on Wordpress: Do-notation considered harmful