So I have a data type sort of like:
data Token = NUM Int | ID String | EOF
and I have a function sort of like:
doStuff list = let
(token, rest) = getToken list
in
....
So what I want to do in the ... part is test if the token I got is a NUM or INT or EOF. I can say token==EOF to test for that case, but I can’t figure out a way to test if the token is a NUM or INT using a conditional, since token==(NUM n) and token==NUM both result in errors. I know that I could write a helper function to do the stuff in the ... and take advantage of pattern matching, but that really hurts the readability of what I’m doing, and it seems like there should be a way to do this check. Anyone know how?
You want a
caseexpression, like:That’s the same sort of pattern matching as you’d get if you defined a function separately.