[Haskell-cafe] Records (was Re: [Haskell] Improvements to
sebastian.sylvan at gmail.com
Fri Nov 18 10:35:13 EST 2005
On 11/18/05, Bulat Ziganshin <bulatz at hotpop.com> wrote:
> Hello Sebastian,
> Thursday, November 17, 2005, 11:02:09 PM, you wrote:
> SS> IMO it really only works well for simple "chains" like "foo . bar .
> SS> oof . rab" but as soon as you start working with functions that take
> SS> more parameters it starts looking very unreadable and you'd be better
> SS> off to just use $ or write out paranthesis and apply arguments
> SS> explicitly, or better yet, introduce some temporary descriptive
> SS> variables in a let or where clause.
> "are you don't like cats? you just don't know how to cook them right!" :)
> -- |Returns length of initial segment of list, conforming to combined condition
> -- F.e. "groupLen (fiSize) (+) (<16*mb) files" returns length of
> -- initial segment of list, containing files with TOTAL size not exceeding 16 mb
> groupLen mapper combinator tester = length . takeWhile tester . scanl1 combinator . map mapper
This is a border line example of what I would consider being abuse of
the (.) operator.
First of all, that line is 96 characters long. A bit much if you ask
me. But still, assuming you're fine with having functions > 80 chars,
it could be written fairly clearly as:
groupLen mapper combinator tester
= length <> takeWhile tester <> scanl1 combinator <> map mapper
where <> = .
Or how about:
groupLen' mapper combinator tester xs
= length $ takeWhile tester $ scanl1 combinator $ map mapper xs
The difference is minimal, if anything I think that writing out the
list argument is actually clearer in this case (although there are
cases when you want to work on functions, and writing out the
parameters makes things less clear).
I'm not saying it's impossible to make good use of (.), I'm saying
that it's not crucial enough to warrant giving it the dot, which in my
opinion is one of the best symbols (and I'd hand it over to record
selection any day of the week!).
I'm also saying that people tend to abuse the (.) operator when they
start out because they think that "less verbose == better", whereas
most people, in my experience, tend to stop using (.) for all but the
simplest cases (such as "filte (not . null)") after a while to promote
readability. I prefer adding a few lines with named sub-expressions to
make things clearer.
More information about the Haskell-Cafe