[nem-en] My thoughts on Nemerle

Alejandro Serrano trupill at yahoo.es
Sat Jan 7 23:57:41 CET 2006


Sorry, this is a very, very long post. Sorry for it, but I has written 
all I think about Nemerle today:

What I expect in next versions of Nemerle:
==========================================

Most of the things I expect in next releases of Nemerle come from C# 
3.0, so I would like to discuss how I think we should implement it, 
because before starting, it would be great to have an agreement.

EXTENSION METHODS

Extension methods are supposed to be some type of method that is invoked 
thorugh a type, but actually resides in another *static* class (module 
in Nemerle).
For creating them, I think C# 3.0 syntax using this before the argument 
type is not needed, just decorating the method with the 
Sytem.CompilerServices.Extension attribute. However, the compiler could 
have some type of checking so extension methods are created only inside 
modules. For example:

module ExtensionExample {
    [Extension] public ToArray[T] (source : IEnumerable[T]) : array[T] {
        ...
    }
}

Another possible approach would be to create extension modules, where 
all public methods get the extension attribute for one type, altough I 
think that way we get less power. Then, inside the class, this would be 
a name for an actual hidden first parameter that would be included in 
all public methods. So:

module Example extends IEnumerable[T] {
    public ToArray[T] () : array[T] {
        // there this referes to the IEnumerable[T]
    }
}

translated to

[Extension] module Example {
    public ToArray[T] (this : IEnumerable[T]) : array[T] {
        ...
    }
}

altough I find this would create a lot of problems with parametric 
polymorphism.

For extension methods use, I think the best way to go is to use "using" 
along with the name of the *class* (not namespace, as in C# 3.0) that 
contains the methods. Maybe some special "import" word can be used.

using System.Query.Sequence;

or

import System.Query.Sequence;

JUST-RETURN FUNCTIONS (LAMBDA EXPRESSIONS IN C#)

I think function syntax is good in Nemerle. However, seen C# 3.0, I 
think its syntax for lambda expressions could be used for functions that 
just return values. I think it can be easiy achieved with:

x => x.Name

could be translated to

fun (x) { x.Name }

Maybe it would conflict with pattern matching?

TYPE INITIALIZERS

This is one of the features I would like the most to see in Nemerle. 
This is just about getting this in constructors:

def r = Point() { X = 1, Y = 3 };

to mean

def r = Point();
r.X = 1;
r.Y = 3;

Another syntax instead { ... } can be used, but I think you get the idea.

NULLABLE TYPES

I don't think it neccessary, although I wouldn't mind to see it. Should 
we use a more difficult typing engine only for getting nullable types? I 
really think not.
Buy maybe some things can be used:

def f : float? = 3.0;

for doing the conversion automatically, instead of:

def f = Nullable(3.0);

which I find stranger.

SUPPORT FOR COMING SYSTEM.QUERY FUNCs

First of all: I tried writing the System.Query libraries for Mono in 
Nemerle, but the Mono guys told be it to write it in C# :-(. Now it's 
completely written but stopped by two bugs in gmcs. However, in MS.NET 
it compiles successfully, so we can do tests.

One of the first things I find in System.Query related to Nemerle in the 
Func generic delegates. May that be the chance to get Nemerle functions 
compatible to C# and the other .NET languages? This has the problem of 
remain compatibility with previous Nemerle functions, but we haven't 
reached 1.0 yet, so we can change it yet ;-). I think this would be a 
great step.
However, I find some difficult thinks on the implementation.

Compute (f : int -> int, x : int) : int {
    f(x)
}

would become:

Compute (f : Func[int, int], x : int) : int {
    f(x)
}

Maybe something like that:

def sum_five = 5 + _;

should get type Func<int, int>?

I think this is very useful for compatibility with other languages, 
something that has not been really achieved in .NET now: Nemerle has one 
set of libraries, Boo some other, F# remains totally in-understandable 
for me :-)

SQL-LIKE QUERY EXPRESSIONS

This has two different parts. First of all, whether we should make lists 
System.Query-compatible or not.
Second, if we should include something like query expressions in 
Nemerle. Maybe, a set of macros could make the work, so it can be easily 
done. The syntax can come from the one in C# spec.

def c = from c in customers
        where c.City == "London"
        select c;

Should translate to:

def c = costumers.Where (fun (c) { c.City == "London" });

But I find that list comprehensions can make its work:

def c = $[c | c in costumers, c.City == "London"];

although grouping and sorting cannot be achieved this way.


Now I will discuss about some things not related to C#, most of them 
seen recently in this mailing list and/or wiki:

STRING FORMATING À LA String.Format

I really find it very useful, but I see the problem of mixing 
not-String.Format-like strings and the other ones. Well, a feature like 
that is always good for everyone.

TRAITS (http://nemerle.org/Traits)

This seems some type of mega-interfaces, aren't they? I woudl prefer 
something like the implementation exposed in 
http://www.iam.unibe.ch/~scg/Archive/Projects/Reic05a.pdf. A set of 
attributes can be created for that aim. An implementation for Rotor can 
be found at http://www.iam.unibe.ch/~scg/Research/Rotor/index.html.

CONTRACTS

Some time ago, I tried to speak to Spec# guys, but in Microsoft Research 
only a few people get into projects (or it seems), so I could not get 
any relevant information. This is, however, really useful.

OPERATOR OVERLOADING

Is this already supported in Nemerle? If it isn't, it would be fine to have.


And one of the most important things, a must for me:

A MACRO-AND-FEATURES-GUIDE

I know there's already a page on the wiki. However, a lot of times I 
think my work would be easier if there were some kind of macro and 
example page. I don't mean something really big, just something like:

List comprehensions:
- $[x | x in list, x < 5]
- $[1, 3 ... 68]

String formatting
- $"Example $x" => substitutes variable x in the string

and so on...
I will start a page on the wiki for it, aiming to make a "quick guide" 
for all Nemerle features, specially for people coming from C# 
(http://nemerle.org/Quick_Guide)

		
______________________________________________ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y moviles desde 1 centimo por minuto. 
http://es.voice.yahoo.com




More information about the devel-en mailing list