Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

I 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.


Depends. 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.


I 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.


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: