[nem-en] recursive types

Wiktor Zychla wzychla at vulcan.edu.pl
Thu Sep 23 14:38:21 CEST 2004


> You can cast Id to Id:
> Abs( Id( "x" ) :> Id, App( Id( "x" ), Id( "y" ) ) );

this does the job. thanks.

another question.

Look at the FVars_Internal method below. it takes two params and returns 
void.

however in one of match branches I call Add method from .NET BCL:

    | Var( name ) =>
     when ( !a.Contains( name ) )
      a.Add( name );

that returns "int". the compiler complains that

"match case body was expected to have type int while it has void"

that's not my intention which is quite opposite. my intention is that all 
match branches have the type "void" while this one has the type "int". 
putting:

    | Var( name ) =>
     when ( !a.Contains( name ) )
      a.Add( name ) :> void;

results in another complaint:

failed to emit value type conversion from System.Int32 to System.Void.

How do I resolve this issue?
Wiktor

--------------------------------------------------------------------------
the code:

variant Lambda {
 | Abs { name : Var; term : Lambda; }
 | App { term1 : Lambda; term2 : Lambda; }
 | Var { name : string;}

 public FVars() : ArrayList {

  def FVars_Internal( l : Lambda, a : ArrayList ) : void  {
   match( l ) {
    | Abs( name, term ) =>
     FVars_Internal( term, a );
     when ( a.Contains( name ) )
      a.Remove( name );
    | App( term1, term2 ) =>
     FVars_Internal( term1, a );
     FVars_Internal( term2, a );
    | Var( name ) =>
     when ( !a.Contains( name ) )
      a.Add( name );
   }
  }
  def a = ArrayList();
  FVars_Internal( this, a );
  a;
 } 






More information about the devel-en mailing list