Pattern matching a rational as defined in Slide 1.2.6 p.4
Since a rational is constructed by storing in vals the numer
and denom
of the irreductible number, different set of arguments in a call to Rational()
would produce the same Rational.
For example :
val x = Rational(4,3)
val y = Rational(8,6)
We would have x==y
.
My question is if we do
x match {
case Rational(numer,denom) =>
// Here
}
with x
defined as above, what values would numer
and denom
have here ? What about the same thing with y
?
From
A constructor pattern
C(p1, ..., pn)
matches all the values of typeC
(or a subtype) that have been constructed with arguments matching the patternsp1, ..., pn
.
I would guess 4
and 3
, in which case does that mean that x
and y
are still "different" despite x==y
being true ?
Thanks