[nem-en] recursive types
Wiktor Zychla
wzychla at vulcan.edu.pl
Thu Sep 23 15:47:36 CEST 2004
yet another question on pattern matching.
how do I tell the compiler that one of branches should have no code (return
void)?
in following scenario:
public Foo( l : Lambda ) : void {
match ( l ) {
| Abs( ... ) => ...
| App( ... ) => ...
| _ => ????
}
}
dropping the "_" branch at all causes the warning "matching non-exhaustive".
to eliminate the warning I guess I need to put something there.
since I expect the match body to return void, I need to put something in
place of ????.
putting the the junk there helps:
public Foo( l : Lambda ) : void {
match ( l ) {
| Abs( ... ) => ...
| App( ... ) => ...
| _ => mutable i = 0; i=1;
}
}
but this in not a solution. could you provide a more elegant one?
interestingly, dropping the "=> body" causes somewhat misleading error:
public Foo( l : Lambda ) : void {
match ( l ) {
| Abs( ... ) => ...
| App( ... ) => ...
| _
}
}
"found junk after pattern"
;)
actually the expected message would be rather "did not find anything after
pattern".
Wiktor
More information about the devel-en
mailing list