At 2001-10-30 11:01, Hal Daume wrote:
obviously i can rewrite:
foo [] = "" foo s = (snd . head) s
but this is uglier.
I'm not sure. I actually prefer it written out so that the number of arguments in the cases matches (as GHC enforces). -- Ashley Yakeley, Seattle WA
Ashley Yakeley wrote:
At 2001-10-30 11:01, Hal Daume wrote:
obviously i can rewrite:
foo [] = "" foo s = (snd . head) s
but this is uglier.
I'm not sure. I actually prefer it written out so that the number of arguments in the cases matches (as GHC enforces).
It's defined in the Report, not a GHC idiosyncracy. As to why, I don't really remember, but I suspect it had to do with a desire by some members of the Haskell Committee to require that the patterns in all clauses of a function binding were disjoint, so that reasoning about programs could deal with each clause independently. This was not adopted, and the alternative top-to-bottom, left-to-right, semantics were, but there was still a feeling that good style demanded disjointness. In that style, the second clause could be written foo ((x,y):xs) = y I don't know whether this is still true, but it used to be argued that this was likely to be more efficient because compilers could produce really good pattern-matching code. --brian
participants (2)
-
Ashley Yakeley -
Brian Boutel