#What am I doing wrong while matching on type patterns?

1 messages · Page 1 of 1 (latest)

dusky flower
#

I'm going through the Exercism track and getting this error from this case clause. It seems to me since I'm specifying with [Wine(color: color, ..rest) that I'd be matching a list where the first element was a Wine with the given color. If I understand the error correctly, it's saying this match condition is identical to [_, ..rest]. Is that right?

Thanks in advance!

rare zinc
#

your match is shadowing your color variable, you need to use a different name in the match and then add an if guard

dusky flower
#

Hmm... it doesn't seem like it's a shadowing issue? I could use an if guard but I was curious if this was the expected behavior when using a match claus this way

rare zinc
#

yes, the 2nd clause is matching everything

viscid verge
#

your middle match pattern matches all possible things

#

you need something like Whine(color: c, ..) if c == color

dusky flower
#

I was expecting given that c==White
match: [Wine(color: White, ...), Wine(color: Red, ...)]
no match: [Wine(color: Rose, ...), Wine(color: Red, ...)]

viscid verge
#

Wine(color: c) creates a new variable c (shadowing), it does not match the existing variable c

dusky flower
#

Oh! That would explain it

viscid verge
#

so thats what you do if c == color for, to make them match