[Haskell-cafe] Re: First time haskell - parse error!
jwlato at gmail.com
Wed Mar 10 06:11:00 EST 2010
> From: Ketil Malde <ketil at malde.org>
> "S. Doaitse Swierstra" <doaitse at cs.uu.nl> writes:
>>> then (s1 ++ s2 ++ s3 ++ s4) where
>>> s1 = "Golds "
>>> s2 = show (gold s g)
>>> s3 = ", Silvers "
>>> s4 = show (silver s g)
>> If you want to keep the definitions local to the expression you should write
> ..but I think it is better style to avoid this kind of one-off named
> values. I much prefer:
> then "Golds "++show (gold s g)++...
> For some reason, this is a style isse that doesn't get much attention,
> at least not in the non-functional language tradition, where temporary
> variables are scattered all over. So instead of doing:
> let ns y = not (isSpace y)
> f x = takeWhile ns x
> in map f
> We can use anonymous functions in place of the uninformatively named
> map (\x -> takeWhile (\y -> not (isSpace y)) x)
> and use partial application toward point-free-ness:
> map (takeWhile (not . isSpace))
I agree, and also tend to this style. Although I sometimes use
one-off named values to avoid line wraps.
For the particular task of combining strings like this, how about
then printf "Golds %s, Silvers %s" (show (gold s g)) (show (silver s g))
It can be a little hard to understand the type at first, but IMHO it
works as expected.
More information about the Haskell-Cafe