Re:The Four Flaws of Haskell
by taylorfausak on Monday August 15, 2016 @08:36AM
(#12289996)
This post explores the differences in those two styles: http://www.yesodweb.com/blog/2015/10/beginner-friendly-code-...
> It seems like my progression as a Haskeller results in forcing myself to write in a harder-to-parse style to make my code shorter, to satisfy some base need for "better" code, even though by most measurements I just made, the longer/explicit/pattern matching code is in fact better.
Re:The Four Flaws of Haskell
by chriswarbo on Monday August 15, 2016 @09:00AM
(#12290100)
To be fair, "<$>" is a synonym for "fmap", so "fmap capitalise readStrLn" is the go-to alternative.
The "do" example is not only more verbose, but less general (it only applies to monads rather than all functors), and relies on special syntax (despite its awkwardness, "<$>" is still just a function call).
You could also do "capitalise `fmap` readStrLn", which is kind of intermediate between the two :)
Re:The Four Flaws of Haskell
by Iceland_jack on Thursday August 18, 2016 @06:07AM
(#12311376)
`ApplicativeDo`[1] do-notation works with Functors
[1] https://downloads.haskell.org/~ghc/master/users-guide/glasgo...
But I've found some of the more common symbols end up being how you think about your code when you become more versed.
The big one is <$> for fmap. If you have some functor/monad/thingy, you'll often be like "I have this pure function that I want to apply to the inner value of my functor", and <$> is the perfect analog to $.
The high abstraction level of Haskell makes reaching for these really tempting and easy. And the alternatives are verbose and harder to read in many situations.
compare "capitalise <$> readStrLn" to
(though "fmap capitalize readStrLn" isn't too bad)