3 ms·
I share this feeling , esp. when each third party lib wants to introduce some variant of <$../<>). But I've found some of the more common symbols end up being
by rtpg 10y ago
I share this feeling , esp. when each third party lib wants to introduce some variant of <$../<>).
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
do val <- readStrLn
return capitalise val
(though "fmap capitalize readStrLn" isn't too bad)
- taylorfausak 10y agoThis post explores the differences in those two styles: http://www.yesodweb.com/blog/2015/10/beginner-friendly-code-and-apis 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.
- chriswarbo 10y agoTo 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 :)
- Iceland_jack 10y ago`ApplicativeDo`[1] do-notation works with Functors [1] https://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#ghc-flag--XApplicativeDo https://downloads.haskell.org/~ghc/master/users-guide/glasgo...