M# - The .NET Language for Technical Computing
M# - The .NET Language for Technical Computing
Overview
M# (“M sharp”) is a new programming language specifically designed for numerical computing on the .NET platform.
Primitive types
In addition to the CLS primitive types, M# defines the following additional types: complex single, complex double, unsigned big integer, big integer, big rational, big float, complex big float.
Generic arithmetic
The implementation of generics in version 2.0 of the .NET Framework does not allow for easy implementation of arithmetic operations on generic types. Although workarounds exist, they are far from trivial and lead to significant additional complexity. It is the one major drawback of generics implementation on the .NET platform.
M# resolves this problem by hiding the complicated implementation details from the developer. This makes generic arithmetic completely transparent.
Public classes using generic arithmetic must be declared if they are not used in the assembly. The name is generated automatically from the type and type parameters.
As an added bonus, M# has the ability to support different arithmetic rules. For example, operations on integers can be performed using modulo arithmetic, allowing for the easy definition of, for example, polynomials over modular fields.
Built-in vector and matrix support
CLR arrays have a limited set of properties and methods. M# encapsulates arrays into vector and matrix types that offer much broader functionality. For example, if an operator is defined for a type, then operations on vectors of the type are implicitly defined as well.
Strong interop support
Over the past half century, a large codebase of numerical software has been developed. It is of primary importance that this code can be accessed easily. Different calling conventions and storage conventions are handled automatically.
Finger Friendly
Whenever possible, the type of variables and functions is inferred from the context.
Assignment by value and by reference
The .NET platform has two kinds of types: value types and reference types. Both kinds have their own rules for assignment. Value types have value semantics: an assignment copies the value of one variable to another. Reference types have reference semantics: assignment copies only the reference, and subsequent changes to one variable also affect the other.
Mathematical objects typically use value semantics. However, in some situations, this can lead to extremely inefficient code. There are two possible remedies.
In M#, normal assignment is by value for scalars and arrays.
A special type of assignment is an assignment by reference to a subarray. The -> operator serves this purpose.
Extended relational operators
In addition to the normal relational operators, M# has operators for “not greater than”, “not less than,” and related operators.
Nested functions and anonymous methods
Performance features
The CLR, and was designed to support the widest possible range of applications. Naturally, trade-offs needed to be made.
The Microsoft .NET languages tend to favor productivity over performance.