SML# - DotNETSMLSharpMapping Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

// mapping .NET/SML#

.NET/SML# is based on OLE/SML# and [[COM Interop|]] feature of .NET.

Mapping between .NET and SML# is also based on
[[mapping between COM and SML#|OLESMLSharpMapping]].

This page describes a part of the mapping scheme which is specific to .NET object access.

!data type mapping.

Data types in C# are mapped to SML# data types as follows.

||! C# types ||! SML# types
||byte || Word8.word
||sbyte ||
||short ||
||ushort || Word32.word
||int ||
||uint || Word32.word
||long ||
||ulong ||
||float || Real32.real
||double || Real64.real
||decimal || OLE.decimal
||char || Word32.word
||string || OLE.string
||bool || bool
||object || OLE.variant
||''t''[] || [SML# type of ''t''] OLE.safearray

!property and field mapping.

Properties and fields of .NET objects are mapped to properties in COM,
and .NET/SML# generates accessor methods for them.

public class Account
    private string name_;
    public string name{
        get{return name_;}
    public int deposit;
    public Account(string n){name_ = n;}

For this '''Account''' class, .NET/SML# generates a getter and a setter of
'''deposit''' and a getter of '''name'''.

type Account = {
   getname : unit  -> OLE.string,
   getdeposit : unit  ->,
   setdeposit : ( -> unit,

!enumeration mapping.

.NET/SML# copies elements of enumerations defined in .NET assemblies
into generated SML# code as 32-bit integers.
For example, an C# enumeration

public enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};

is converted to

val Days_Sat = 1 :
val Days_Sun = 2 :
val Days_Mon = 3 :
val Days_Tue = 4 :
val Days_Wed = 5 :
val Days_Thu = 6 :
val Days_Fri = 7 :

The default type of elements of an enumeration in C# is int.
.NET/SML# casts elements of an enumeration of other type to 32-bit signed

public enum UIEnum : uint {UIMAX = 0xFFFFFFFF};

is converted to

val UIEnum_UIMAX = ~1 :

!Topics in .NET/SML#.