[Haskell-cafe] Language complexity & beginners
Joachim Durchholz
jo at durchholz.org
Tue Feb 9 12:17:22 UTC 2016
Am 09.02.2016 um 12:27 schrieb Kosyrev Serge:
> Case in point (only slightly contrived) -- which one is easier to
> visually parse to you:
>
> foo (thInt $ fromIntegral $ c2hsValueInt cexp) (thInt $ fromIntegral $ c2hsValueInt cexp)
>
> foo (thInt (fromIntegral (c2hsValueInt cexp))) (thInt (fromIntegral (c2hsValueInt cexp)))
You can always denest by naming subexpressions.
e.g.
let subexpr = thInt (fromIntegral (c2hsValueInt cexp)))
in foo subexpr subexpr
or
let subexpr = (thInt . fromIntegral . c2hsValueInt) cexp
in foo subexpr subexpr
or
let fn = thInt . fromIntegral . c2hsValueInt
in foo (fn cexp) (fn cexp)
I routinely do that kind of denesting as soon as a line goes beyond 72
characters. I have found that such code is usually far easier to read
regardless of what I'm doing in the line.
I think the problem is not that you cannot write readable code, it is
that people do not use existing facilities for that.
If that's correct, then adding another facility for the same purpose is
unlikely to help.
More information about the Haskell-Cafe
mailing list