[nem-en] recursive types
Kamil Skalski
nazgul at nemerle.org
Thu Sep 23 16:09:07 CEST 2004
On Thu, Sep 23, 2004 at 03:47:36PM +0200, Wiktor Zychla wrote:
> 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".
:) Probably we should make it more user-friendly message.
Kamil
More information about the devel-en
mailing list