Sunday, January 2, 2011

Nemerle: Functional + OO

In my quest for language discovery, I have run into Nemerle:

"Nemerle is a 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 meta-programming system."

It has some really cool features: functional values, variants and pattern matching, type inference, and a powerful macro system. In some regards, it's very similar to Scala. Example:

variant RgbColor {
  | Red
  | Yellow
  | Green
  | Different {
      red   : float;
      green : float;
      blue  : float;
    }
}

string_of_color (color : RgbColor) : string
{
  match (color) {
    | RgbColor.Red    => "red"
    | RgbColor.Yellow => "yellow"
    | RgbColor.Green  => "green"
    | RgbColor.Different (r, g, b) => $"rgb($r, $g, $b)"
  }
}