Removal candidates in patterns
Olaf Chitil
O.Chitil at kent.ac.uk
Thu Jan 26 15:56:06 EST 2006
Duncan Coutts wrote:
>I think it's a perfectly reasonable mental model for people to believe
>that:
>data Char = 'a' | 'b' | 'c' | ...
>data Int = ... -2 | -1 | 0 | 1 | 2 | ...
>
>I don't see why we should remove one and not the other. Students will
>ask why the can pattern match on strings, characters and booleans but
>not numbers.
>
>
Numbers are special because they are overloaded. A numeric literal is an
element of many types. That clearly distinguishes them from other literals.
>Perhaps primitive recursion on integers is misleading, but people will
>still write
>
>foo n | n == 0 = ...
> | otherwise = ...
>
>where they previously wrote
>
>foo 0 = ...
>foo n = ...
>
>so what have we gained except less notational convenience?
>
>
Discourage anyone from teaching primitive recursion on integers.
Recursion on integers then has to be taught as a separate topic, giving
opportunity to point out the pitfalls. Sure, it doesn't prevent anyone
from writing anything.
>Not all pattern matching on numeric literals is involved with recursion
>on integers, where as virtually all n+k patterns is used for that
>purpose.
>
I think there are very few situations where you would use k patterns
without recursion.
>So there is some distinction between the two forms. n+k
>patterns are a quirk of the numeric types. k patterns are regular with
>other types in the language.
>
>
As I said above, they are not regular because of overloading.
>It's partly the complexity of the language and partly because our latest
>language spec (H98) is not the language that we all use (H98 + various
>extensions). I'm sure Haskell-prime will help in this area.
>
>
I hope as well that Haskell' will be the language that most people will
use and some extensions are certainly required for practical use. I just
want to get rid of superfluous features.
Ciao,
Olaf
More information about the Haskell-prime
mailing list