[mercury-users] .NET Mercury type representation.

Fergus Henderson fjh at mercury.cs.mu.oz.au
Sat Mar 1 00:53:37 AEDT 2003


On 28-Feb-2003, Richard A. O'Keefe <ok at cs.otago.ac.nz> wrote:
> I am not familiar with C#.  Here's how I would do it in Java.
>     abstract class T { abstract int tag(); }
>     class T_F extends T { int tag() { return 0; } int x1; object x2; }
>     class T_G extends T { int tag() { return 1; } int x2;            }
> 
> 	Personally I just wish that .NET choose to make algebraic types
> 	directly representable in the framework.
> 	
> The mapping of algebraic types onto Java shown above is pretty direct:
> a class for each type with a subclass for each constructor.  If there
> is only one constructor, the "type" and "constructor" classes fuse and
> there is no tag() method.
> No wasted space.  The Java tag represents the Mercury tag.
> Isn't such a mapping possible for C#?

Yes, that would be possible in C# (or in IL, the .NET CLR intermediate
language -- we compile to IL, not to C#).

That representation is more space-efficient than our current representation.
It is a little less time-efficient, because getting the tag requires a
virtual function call (which typically requires two loads, an indirect
jump, and a return) rather than just loading a field.  But nevertheless
this might well be a better trade-off overall than our current scheme.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list