[Haskell-cafe] Language complexity & beginners
jo at durchholz.org
Tue Feb 9 18:11:57 UTC 2016
Am 09.02.2016 um 18:24 schrieb Kosyrev Serge:
>>> foo (thInt (fromIntegral (c2hsValueInt cexp))) (thInt (fromIntegral (c2hsValueInt cexp)))
> I clearly made a mistake of duplicating a real expression.. should have
> picked two different expressions for an example.
The counterexamples still work.
foo (thInt1 (fromIntegral1 (c2hsValueInt1 cexp1))) (thInt2
(fromIntegral2 (c2hsValueInt2 cexp2)))
can still become this:
let int1 = thInt1 (fromIntegral1 (c2hsValueInt1 cexp1))
int2 = thInt2 (fromIntegral2 (c2hsValueInt2 cexp2))
in foo int1 int2
and that's perfectly readable in my book.
If you don't like the nested parentheses, use function composition:
let fn1 = thInt1 . fromIntegral1 . c2hsValueInt1
fn2 = thInt2 . fromIntegral2 . c2hsValueInt2
in foo (fn1 int1) (fn2 int2)
Function composition isn't the main tool though; I found that naming
subexpressions always works, plus the names can help with readability if
they are chosen wisely.
More information about the Haskell-Cafe