[nem-en] recursive types
Kamil Skalski
nazgul at nemerle.org
Thu Sep 23 16:02:01 CEST 2004
On Thu, Sep 23, 2004 at 02:38:21PM +0200, Wiktor Zychla wrote:
> >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"
Right, the 'when' condition is equivalent to
if (cond) body else ();
which means that body should have type void.
The easiest way to ignore the value is
when (!a.Contains (name))
ignore (a.Add (name))
ignore (e) is equivalent to
def _ = e;
()
where () is the empty expression of type void (which you asked for in
another mail)
The message here is somewhat misleading and should be changed to
something like
'when body is not void, use `ignore` to ignore the value'
>
> 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?
Well, void is just a language way to say that there is no result. You
cannot simply cast something to void, because AFAIK there is no such
thing in runtime.
KAmil
More information about the devel-en
mailing list