   The Nemerle programming language: C# meets ML
  Yesterday in #ankhsvn, someone gave me the link to the homepage of the Nemerle programming language. It is a hybrid functional/object-oriented language which borrows a lot of the basic syntax from C#, but also provides most of the things you would expect from a language in the ML family, such as type inference, pattern matching, macros, lambda functions, functions as types, a module system, generic types etc etc...Of course, this is not the first ML language that runs on the CLR(F# and SML.NET are the two I know of), but I think this language has a couple of advantages that could give it a better chance:* It is very easy to get into if you already know C#/C++/Java. You can mostly just write in the same style you would in those languages at first, then incorporate the functional features gradually as you learn them.* Since it''s running on .NET(and should be a full CLS consumer/producer soon), it can basically be plugged in wherever you would otherwise use C#/VB.NET.Here''s an example of a nemerle program:   /* * Longest Common Subsequence */using System;class IntArray2D {  private mutable _m : Array;  public this (w : int, h : int)   {    _m <- Array.CreateInstance (typeof (System.Int32), w + 1, h + 1);  }    public Get (x : int, y : int) : int   { (_m.GetValue (x, y) :> int)  }    public Set (x : int, y : int, value : int) : void   { _m.SetValue (value, x, y)  }}class LCS{  private static Max (x : int, y : int) : int   { if (x < y) y else x;  }    private static Max (x : int, y : int, z : int) : int   { Max (Max (x, y), z)  }    private mutable _M : IntArray2D;  private mutable _l : array (char);  private mutable _r : array (char); private Step (i : int, j : int) : int   {    if (i == 0 || j == 0){_M.Set (i, j, 0); 0    }    else {  def value =   if (_l [i - 1] != _r [j - 1]) Max (Step (i, j - 1), Step (i - 1, j))   elseMax (Step (i - 1, j - 1) + 1, Step (i - 1, j), Step (i, j - 1));    _M.Set (i, j, value); value    }  } public this (l : string, r : string)   { Console.WriteLine ("Calculating LCS of {0} and {1}...", l, r);   _M <- IntArray2D (l.Length, r.Length);    _l <- l.ToCharArray ();    _r <- r.ToCharArray ();   printf ("%d\n", this.Step (l.Length, r.Length));  } public static Main () : void   { def _ = LCS ("alamakotazz", "komarezzk");    def _ = LCS ("axbyczd", "exfygzh");   ()  }}I say it''s cool. What do other people think?   --AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [Blog] [RSS] [Browse the source] [IRC channel] 
  I had a look at the code and the site and must admit that I really don''t like the changing of basic symbols we all take for granted (eg: = replaced with <- .... wtf?).The syntax doesn''t look like something I''d want to grip. ;  It looks interesting, but the type inferencing seems rather weak in comparison to real ML languages, apparently only allowing bottom-up types rather than top-down. Their concession to only do function-internal type inferencing also weakens the ability to use compile-time polymorphic functions, it seems. It also seems to lack the cool currying and pattern-matching syntax that I grew to like in ML, although it claims to use some "eta-long" partial function application (currying), so I guess it''ll create a closure properly. I personally prefer using <- for assignment, because of the confusion that can arise over = vs == in code. ;quote:Original post by downgraded   I had a look at the code and the site and must admit that I really don't like the changing of basic symbols we all take for granted (eg: = replaced with <- .... wtf?).The syntax doesn't look like something I'd want to grip.   The choice of = for assignment is as equally arbitrary as choosing <-. You are just used to C++. If you grew up on Pascal you'd think that assignment without a colon looked goofy. There's a lot more to the language than the syntax. Functional language features are creeping into modern imperative languages ever so slowly.This is the kind of thing you'd see on Lambda, I'm surprised it isn't on there (unless its been on there before). They like their functional languages, although I'm sure someone will roll their nose at the mixture of imperative and functional styles.   [edited by - antareus on February 12, 2004 3:52:01 PM];quote:Original post by Assassin   It also seems to lack ... pattern-matching syntax that I grew to like in MLFrom what I can see, it does support ML-style pattern matching. ;  I like it a lot.I must admit to agreeing with downgraded over the use of "<-". It looks like "=" and "<-" could never be valid in the same place, so I don''t see the need to introduce new syntax.I also wonder if the compiler wouldn''t be able to determine when a ''variable'' needs to be mutable, so you''d only need the "def" declaration. ;  OMG.....SML.NET ??I have to learn sml because of my study...it''s a real pain Is this language really used in commercial software?;quote:Original post by Tom Friedl  OMG.....SML.NET ??I have to learn sml because of my study...it''s a real pain Is this language really used in commercial software? Does that make it any more or less viable to learn? In programming languages, just like everything else, it is the average languages that usually rise to the top. ;quote:Original post by Tom Friedl  I have to learn sml because of my study...it''s a real pain  Learning SML will be good for you, no matter what language you are using. It helps you think about software and program design in ways you would never come up with if you always restricted yourself to, say, C++. At least learning SML was good for me - YMMV. ;  meh...there are something like half a dozen NET based ML languages...even Microsoft Research has one. 