5 ms·
I always assumed that do-notation had been introduced in Haskell as soon as monads became a thing, but no: this paper dates from 1995, while do-notation appeare
by hanslub42 6y ago
I always assumed that do-notation had been introduced in Haskell as soon as monads became a thing, but no: this paper dates from 1995, while do-notation appeared with the Haskell 1.3 report in 1996. So here all the monadic actions are threaded together with thenST (a specialised version of >>=)
Skimming this article really made me appreciate the compactness and clarity of do-notation (although hard-core Haskellers will object that it hides what really is going on)
- marcosdumay 6y ago> although hard-core Haskellers will object that it hides what really is going on I've never seen anybody say this. Many people say that when learning you must avoid it a few times to understand it, but I never saw anybody claiming it hides things for experienced developers. Also, I think the idea is very far fetched, expanding do notation on your head when reading code is one of the minimum skills to make proper use of the language, thus it can't hide anything to hard-core Haskellers. Anyway, if you think your program is better structure using do, use it and don't stop to listen to criticism.
- hanslub42 6y agoI agree 100%. But see: https://wiki.haskell.org/Do_notation_considered_harmful https://wiki.haskell.org/Do_notation_considered_harmful
- danidiaz 6y agoI believe that negative view of do notation is not popular nowadays. The tendency is to lean more on it. There are language extensions like ApplicativeDo and the newer QualifiedDo which expand the reach of the notation.
- marcosdumay 6y agoOh, but notice that all those reported problems either have the "newcomers" word on them or are cases of your code having a worse structure due to it. Also GHC now has features to revert all the bad structure problems cited there. There is no wildcard advice of "use do notation" or "avoid do notation" possible. It's an incredibly handy tool, but you need to decide for yourself if it improves your code or not.
- The_rationalist 6y agoMy "teacher" (a cargo cult "craftman") banned the use of do among other ivory tower extremisms.
- ABeeSea 6y agoI’ve seen some pretty broken do statements from attempts to use parsec. The applicative syntax just makes more sense in describing what is happening; especially for more complicated parsing logic.
- garethrowlands 6y agoI agree that Applicative syntax is good for parsing. But I'd add that not all parsers can be applicative, so occasionally you do need do notation in your parser.