Linearity Requirement for Patterns
Sat, 17 Mar 2001 22:22:46 +1300
Dylan Thurston wrote:
> Only numeric literals actually use the '==' operator, correct?
> (As opposed to built-in equality for data constructors and characters.)
I should have been more specific. Not that it affects the point being
made, and I didn't want to lose that in the detail.
Pattern matching for numeric literals uses whatever (==) has been
defined for the type, except, of course for the literals in n+k patterns
where (>=) is used.
The Character type is treated as a set of data constructors. Data
constructors match if they are the same constructor, and fail to match
otherwise. This is not the same as equality, where you are free to
define any result when comparing values, but it is the same as the
equality that would be derived for a type that consisted of a set of
String literals are lists of characters. Consequently, string matching
will use constructor matching for the List constructors and for the
So, yes, (==) is used when matching most numeric literals, and not used
for other literals.