Nemerle - gregorymorrison/euler1 GitHub Wiki
From Wikipedia: Nemerle is a general-purpose high-level statically typed programming language for the .NET platform. It offers functional, object-oriented and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system. Nemerle, introduced in 2003, has optional typing, optional classes, optional functions. You can write your code in C# style, ML style, etc.
I didn't have too bad a time writing this version of Euler1; it's a direct translation of my [Standard ML](https://github.com/gregorymorrison/euler1/wiki/ standard-ml) version. It took maybe an hour to get the compiler to stop complaining:
// Euler1 in Nemerle
using System.Console;
def Euler1(x: int, acc=0: int): int {
match (x) {
| 1 => acc
| x when x%3==0 => Euler1(x-1, acc+x)
| x when x%5==0 => Euler1(x-1, acc+x)
| _ => Euler1(x-1, acc)
}
};
WriteLine( Euler1(999) );
And here's an OOP version. I modified just enough of my first C# version to get it to compile. It's mostly the same, though by default member variables are constant and need to be declared mutable:
// Euler1 in Nemerle
using System.Console;
class Euler1 {
mutable size : int;
mutable result : int;
public this(size : int) {
this.size = size;
}
public solve() : void {
this.result = 0;
foreach (i in [1 .. size]) {
when (i%3==0 || i%5==0) {
this.result = this.result + i;
}
}
}
static Main() : void {
def euler1 = Euler1(999);
euler1.solve();
WriteLine(euler1.result);
}
}
To execute, I used Mono. I simply used Yum to install mono-basic.i686. Then, I compiled my code with Nemerle's compiler ncc and executed it with mono:
$ ncc euler1.n
$ mono out.exe
233168