4 ms·
I like them. It's not that I don't like point-free functions but more often than not specifying the point makes sense in my opinion — more clarity, less beauty.
by davnn 10y ago
I like them. It's not that I don't like point-free functions but more often than not specifying the point makes sense in my opinion — more clarity, less beauty.
- JoshTriplett 10y agoI agree. My general rule is that any non-trivial use of "flip" or any use of curried '.' or '$' means I should name the point instead.
- eru 10y agoDepends. I like using (.) for eg chaining functors, even though it's not trivial: (fmap . fmap . fmap) toUpper is a function that goes three levels down and applies f, eg on a 'Maybe (Int, [Char]))' and I find this style easier to read than: fmap (\i_string -> fmap (\string -> fmap (\c -> toUpper c))) But chaining 'fmap's in this way might be a special idiom that people can get used to, and not say anything about using point-free style in novel situations. The nice thing is that you can mix 'fmap' and eg 'traverse' like this.
- JoshTriplett 10y agoI think in that case, for clarity, I'd rather write: f (Just (i, cs)) = Just (i, map toUpper cs) f x = x Especially because I find the instances that apply fmap to the second item of a two-item tuple confusing. But in general I don't mind that kind of use of '.'; I was talking more about any expression like "g . (f .)" or similarly inscrutable curries.
- eru 10y agoThe chained Functors, Traversables etc are useful when you are still writing and changing your code---it's really easy to add or remove a layer. Yes, some of the instances can be confusing. Adding type signatures afterwards usually clears it up. (The types will tell the reader that for tuples, fmap operates on the second element.) Yes, "g . (f .)" might be a bit harder to read. Though when I first discovered functor-composition by myself, I was just playing around with exactly that kind of point-less nonsense for fun.