The Nemerle Project Blog The Blog http://nemerle.org/blog/index.html University of Wroclaw feedback@nemerle.org Mon, 08 Jan 2007 17:37:21 GMT http://backend.userland.com/rss lb# 23 Jul 2006: Late binding <p> Recently one of <a href="http://snaury.googlepages.com/">Nemerle users</a> played a little bit with our macro system and implemented a feature allowing dynamic invocation of methods or accessing properties in a quite clean way (as you probably know, Nemerle is entirely statically typed and forces your code to be compliant with .NET standard object-oriented access to classes). The simplest example is </p> <xmp class="code-csharp"> def getLength (obj : object) late obj.Length System.Console.WriteLine (getLength ("Grey goo")) System.Console.WriteLine (getLength ([1,2,3])) System.Console.WriteLine (getLength (System.Windows.Forms.LinkArea ())) </xmp> <p> Here we just want a method to fetch the <em>Length</em> property of given object and <em>late</em> keyword introduced by macro allows us to do so easily. The biggest advantage here is that we do not care about the intefaces and common supertypes of object we use this on, so we can apply this method to <em>ANY</em> object (which is assumed to contain the correct property). The call will be made using .NET's <a href="http://www.devx.com/dotnet/Article/7004/0/page/2">dynamic invocation</a> feature. </p> <p> The idea is a little bit similar to something called <a href="http://en.wikipedia.org/wiki/Duck_typing">duck typing</a> (though the name is a bit politically controversial in my country at the moment ;p), but in case of our macros it works in a different way. We do not introduce any dummy "types" for objects, which are not type-checked, but we allow user to specify which parts of code should be dynamic (for more detailed specification see a <a href="http://nemerle.org/Late_Binding_Macro">deciated page</a>). </p> <p> Now the question is why is it really useful? In general I'm always heading towards the perfect world and I prefer my programs to be proved being perfect and safe. Type inference is a powerful Nemerle's feature, which helps here - I do not need to specify types of variables and compiler can infer what I mean; if it can't, it usually means I made some mistake. But here comes the problem, sometimes the code we write is simply not compatible with language / platform type system and compiler complains about my code even though I know it is right. Let us consider another example: </p> <xmp class="code-csharp"> #pragma indent using Nemerle.Late public class Pixel mutable shift = 0 public Draw () : void System.Console.Write (string (' ', shift)) System.Console.Write ("*") public Move (dx : int) : void shift += dx public class Triangle public Draw () : void System.Console.Write ("/^\\") def perform (x : object, with_move = false) late x.Draw () when (with_move) x.Move (5) x.Draw () System.Console.WriteLine () perform (Pixel (), true) perform (Triangle ()) </xmp> <p> Now as you can see my <em>perform</em> function is quite tricky - it does not call <em>Move</em> on object if I do not specify <em>with_move</em> parameter to be true. So its contract is something like "calls Draw, but if we want move also calls Move", which is not expressible in any simple type system (e.g. .NET). With our late binding macro we just ignore the type system and perform all calls dynamically. :) </p> <p> One more thing to notice here is that usually we can avoid dynamic calls by using well designed object hierarchy and interfaces (if we are not too lazy of course ;) ). In our example we can easily make the call to <em>Draw</em> statically safe, by introducing the <em>IDrawable</em> interface. </p> <xmp class="code-csharp"> public interface IDrawable Draw () : void public class Pixel : IDrawable mutable shift = 0 public Draw () : void System.Console.Write (string (' ', shift)) System.Console.Write ("*") public Move (dx : int) : void shift += dx public class Triangle : IDrawable public Draw () : void System.Console.Write ("/^\\") def perform (x, with_move = false) x.Draw () when (with_move) late x.Move (5) x.Draw () System.Console.WriteLine () </xmp> <p> Note that now type inference comes in help - the signature <em>perform (x : IDrawable, with_move : bool) : void</em> is automatically guessed by compiler. The only late bound operation now is a call to <em>Move</em>. To solve this we could do two things: </p> <ul> <li>write a specialized perform_with_move function, which would take <em>IMovable</em> or simply <em>Triangle</em>, but this would yield code duplication and additional efforts </li> <li> cast to more specific type before calling Move, which makes your code a little bit uglier and you must know exactly which type to cast to. </li> </ul> <p> The other cases when late binding might be useful is when you use a platform's feature, which is very dynamic by nature - like using types obtained through COM. </p> <div align='right'><a href='http://nemerle.org/blog/archive/2006/Jul-23.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2006/Jul-23.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2006/Jul-23.html Sun, 23 Jul 2006 13:55:00 GMT 16 May 2006: Nemerle 0.9.3 hits The Outside World <p> We now require mono 1.1.13 or newer (or MS.NET 2.0 as usual). </p> <ul> <li> Limited support for Nullable type: <ul> <li> using nullable syntax (<tt>int?</tt>, <tt>MyStruct?</tt>), </li><li> autoconversion of null and values to <tt>Nullable[T]</tt> (<tt>null : double?</tt>, <tt>66 : int?</tt>) </li><li> <tt>==</tt> and <tt>!=</tt> operator with <tt>null</tt> literal (<tt>x == null</tt>, <tt>y != null</tt>) (using operators on two nullable instances doesn't work yet) </li> </ul> </li><li> <a href="http://nemerle.org/Extension_methods">Extension methods</a> </li><li> <tt>using (def x = ...)</tt> now works. </li><li> Fixes in casts involving generic types. </li><li> We do not consider void subtype of object anymore. We also do not allow <tt>void</tt> to be type parameter of generic types. This seems to have caused more trouble than it's worth. </li><li> Better message for errors in calls. </li><li> Updates of Nemerle Emacs mode. </li><li> Arrays are now considered subtypes of <tt>IEnumerable</tt> and the like. </li><li> One can now say class <tt>A[T] where T : enum</tt>. </li><li> Types can be nested in variants now. </li><li> Default stack size on MS.NET should not cause problems (with Out of memoery exn) now. </li><li> <tt>(x, y) =&gt; expr</tt> can be used in place of <tt>fun (x, y) { expr }</tt>. </li></ul> <p> Library changes:</p> <ul><li> Optimizations in RList. </li><li> Value/HasValue in option. </li><li> Heap and Set now implement ICollection[T]. </li><li> Methods from NArray and NString are now extension methods. </ul> <p> Macro library changes:</p> <ul> <li> Record macro can now be forced to exclude/include fields. </li> </ul> <p> Backward incompatible library changes:</p> <ul> <li> The NC.Hashtable indexer was changed to follow SCG.Dictionary behavior of throwing exception when the key is not found. </li></ul> <p> Fixed issues from BTS: </p> <ul><li><a href="http://nemerle.org/bugs/view.php?id=338">#338</a>: Caching in ++x macro do not play nice with valuetypes </li><li><a href="http://nemerle.org/bugs/view.php?id=416">#416</a>: allow extending existing classes </li><li><a href="http://nemerle.org/bugs/view.php?id=503">#503</a>: Cannot do type match on 'a </li><li><a href="http://nemerle.org/bugs/view.php?id=547">#547</a>: generic constraint 'a : 'b and static instance problem </li><li><a href="http://nemerle.org/bugs/view.php?id=575">#575</a>: Tail calls optimization causes invalid IL to be generated </li><li><a href="http://nemerle.org/bugs/view.php?id=588">#588</a>: Nullrefence in runtime for yields in try block </li><li><a href="http://nemerle.org/bugs/view.php?id=589">#589</a>: ICE in Typer for locked yield </li><li><a href="http://nemerle.org/bugs/view.php?id=590">#590</a>: ICE in Check STV for generic delegates </li><li><a href="http://nemerle.org/bugs/view.php?id=591">#591</a>: Typer ICE for type check involving generic type </li><li><a href="http://nemerle.org/bugs/view.php?id=594">#594</a>: bogus "ambiguous type" message </li><li><a href="http://nemerle.org/bugs/view.php?id=595">#595</a>: too rigid protected member checking in nested types </li><li><a href="http://nemerle.org/bugs/view.php?id=598">#598</a>: LookupInternalType does not check the supported size of Function object </li><li><a href="http://nemerle.org/bugs/view.php?id=604">#604</a>: compile error(mono svn 56155 and nemele svn 6088) </li><li><a href="http://nemerle.org/bugs/view.php?id=605">#605</a>: Casts from value type to 'a causes invalid IL </li><li><a href="http://nemerle.org/bugs/view.php?id=606">#606</a>: possible problem with loop closures </li><li><a href="http://nemerle.org/bugs/view.php?id=607">#607</a>: typo in sqlmacro </li><li><a href="http://nemerle.org/bugs/view.php?id=608">#608</a>: lazy literals </li><li><a href="http://nemerle.org/bugs/view.php?id=609">#609</a>: System.Bool instead of System.Boolean </li><li><a href="http://nemerle.org/bugs/view.php?id=612">#612</a>: code generation problem with uint </li><li><a href="http://nemerle.org/bugs/view.php?id=613">#613</a>: Ncc crushes during the compilation process </li><li><a href="http://nemerle.org/bugs/view.php?id=614">#614</a>: Record to generate constructor just for not initialized fields </li><li><a href="http://nemerle.org/bugs/view.php?id=617">#617</a>: optional regexp match </li><li><a href="http://nemerle.org/bugs/view.php?id=618">#618</a>: -0 causes compilation error </li><li><a href="http://nemerle.org/bugs/view.php?id=620">#620</a>: MainParser.ParseExpr("def f(){}") and MainParser.ParseExpr("") cause NullReferenceException </li><li><a href="http://nemerle.org/bugs/view.php?id=621">#621</a>: SomeFunction(throw Exception()) produces invalid IL </li><li><a href="http://nemerle.org/bugs/view.php?id=622">#622</a>: ICE for polymorphic property used in matching </li><li><a href="http://nemerle.org/bugs/view.php?id=623">#623</a>: probably more array tweaks required </li><li><a href="http://nemerle.org/bugs/view.php?id=624">#624</a>: Internal compiler error for $ outside quotations </li><li><a href="http://nemerle.org/bugs/view.php?id=625">#625</a>: strange error when misusing macro-generated type </li><li><a href="http://nemerle.org/bugs/view.php?id=626">#626</a>: Quoted declaration of method override results in compile-time error </li><li><a href="http://nemerle.org/bugs/view.php?id=627">#627</a>: Increment in argument </li><li><a href="http://nemerle.org/bugs/view.php?id=628">#628</a>: Ugly error message (for list[void]) </li><li><a href="http://nemerle.org/bugs/view.php?id=630">#630</a>: Implicit conversions doesn't work for generic parameter </li><li><a href="http://nemerle.org/bugs/view.php?id=631">#631</a>: Patch for quoted declarations to support ellipsis in class/interface members declaration </li><li><a href="http://nemerle.org/bugs/view.php?id=636">#636</a>: lock (expr) will evaluate expr twice </li><li><a href="http://nemerle.org/bugs/view.php?id=637">#637</a>: Compiler skips some classes during compilation </li><li><a href="http://nemerle.org/bugs/view.php?id=639">#639</a>: A compile-time calculus and code generation </li><li><a href="http://nemerle.org/bugs/view.php?id=641">#641</a>: Compiler crash due to function to delegate conversion inside generic class </li><li><a href="http://nemerle.org/bugs/view.php?id=642">#642</a>: Error if list declared without initialisation </li><li><a href="http://nemerle.org/bugs/view.php?id=644">#644</a>: Wrong behavior during base ctor call </li><li><a href="http://nemerle.org/bugs/view.php?id=645">#645</a>: Nemerle.DesignPatterns.ProxyPublicMembers error </li><li><a href="http://nemerle.org/bugs/view.php?id=647">#647</a>: problems with preprocessor and the $ macro </li><li><a href="http://nemerle.org/bugs/view.php?id=648">#648</a>: Wrong error message when interface implementation is not complete </li><li><a href="http://nemerle.org/bugs/view.php?id=649">#649</a>: Can't provide generic constraint in quoted declaration </li><li><a href="http://nemerle.org/bugs/view.php?id=650">#650</a>: Attribute compilation error. </li><li><a href="http://nemerle.org/bugs/view.php?id=652">#652</a>: Generic parameter names can't be used inside quoted declaration </li><li><a href="http://nemerle.org/bugs/view.php?id=653">#653</a>: Empty interface can't be defined from macro </li><li><a href="http://nemerle.org/bugs/view.php?id=654">#654</a>: Makefile, install target </li><li><a href="http://nemerle.org/bugs/view.php?id=656">#656</a>: Assembly attribute don't gets added from assembly-level macro-attribute </li><li><a href="http://nemerle.org/bugs/view.php?id=657">#657</a>: Unhandled Exception: Nemerle.Core.MatchFailureException in ncc </li><li><a href="http://nemerle.org/bugs/view.php?id=658">#658</a>: Trying to parameterize non-generic type shows up a lot of vagu error messages </li><li><a href="http://nemerle.org/bugs/view.php?id=661">#661</a>: extension method can not find member. </li><li><a href="http://nemerle.org/bugs/view.php?id=662">#662</a>: C#3.0 like lambda expression operator priority </li><li><a href="http://nemerle.org/bugs/view.php?id=663">#663</a>: ASP.NET functionality broken on Windows platform </li><li><a href="http://nemerle.org/bugs/view.php?id=666">#666</a>: Can't build sources from latest snapshot (r6245) </li><li><a href="http://nemerle.org/bugs/view.php?id=667">#667</a>: "make install" doesn't install Nemerle assemblies into GAC </li><li><a href="http://nemerle.org/bugs/view.php?id=668">#668</a>: msbuild cannot build Nemerle.sln </li><li><a href="http://nemerle.org/bugs/view.php?id=669">#669</a>: Cannot install a snapshot </li><li><a href="http://nemerle.org/bugs/view.php?id=670">#670</a>: Can't set the value of byte array element with index not divisible by 4 without explicit cast. </li><li><a href="http://nemerle.org/bugs/view.php?id=671">#671</a>: Problem with resources included into assembly </li><li><a href="http://nemerle.org/bugs/view.php?id=672">#672</a>: Compiler reports non-existence of a namespace, althougth it exists. </li><li><a href="http://nemerle.org/bugs/view.php?id=674">#674</a>: type inference cannot guess. </li><li><a href="http://nemerle.org/bugs/view.php?id=675">#675</a>: ExtensionAttribute's namespace on System.Query.dll. </ul> <div align='right'><a href='http://nemerle.org/blog/archive/2006/May-16.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2006/May-16.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2006/May-16.html Tue, 16 May 2006 13:55:00 GMT 24 Jan 2006: Nemerle 0.9.2 in the wild <p> This version brings a bunch of new features and of course several bugfixes. We now require mono 1.1.11+ or MS.NET 2.0. About 180 svn commits were done since the last release. </p> <p> New language features: </p> <ul><li> Generators aka <a href="http://nemerle.org/Yield">yield support</a> </li><li> <a href="http://nemerle.org/List_comprehensions">List comprehensions</a> + ranges </li><li> <a href="http://nemerle.org/Extensible_matching">Extensible pattern matching</a> </li><li> 'this' can be now used as the full type (including type parameters) of the current class. </li><li> Matching directly in function parameters, it is now possible to say: <xmp class="code-csharp"> def foo (x, (y, z)) { ... } def bar ((a, b), (c, d, e)) { ... } </xmp> </li> </ul> <p> Macros: </p> <ul><li> New package of profiling macros: http://nemerle.org/Profiling_macros </li><li> Extensions in logging macros: http://nemerle.org/Logging_macros </li><li> <a href="http://nemerle.org/Design_patterns#Macro_included_in_standard_library"> Nemerle.DesignPatterns.ProxyPublicMembers</a> macro has been added </li></ul> <p> Library: </p> <ul> <li> New RList module (Random Access Lists as described by Chris Okasaki), by Wojtek Knapik. </li></ul> <p>Other:</a> <ul><li> -main flag in ncc for specifying entry point. </li><li> Kinda hackish support for ASPX/ASMX in cs2n. </li><li> NoiseEHC contributed a fix to MSBuild task, which is necessary for VS plugin development </li></ul> <p> Bugfixes:</p> <ul><li> Always use at least 16M of stack when compiling on MS.NET (should fix stack overflow errors). </li><li> Fix foreach on multidimensional arrays. </li><li> XSP2 fixes by Kanru Chen. </li></ul> <p> And from <a href="http://nemerle.org/bugs/">mantis</a>:</p> <ul><li><a href="http://nemerle.org/bugs/view.php?id=593">#593</a>: we don't save mutable attribute for fields </li><li><a href="http://nemerle.org/bugs/view.php?id=587">#587</a>: Generator Enumerable is incorrectly created </li><li><a href="http://nemerle.org/bugs/view.php?id=518">#518</a>: matching directly function parameters </li><li><a href="http://nemerle.org/bugs/view.php?id=529">#529</a>: Support for generators </li><li><a href="http://nemerle.org/bugs/view.php?id=584">#584</a>: Compiler crash when using an array initialiser with mixed types of initialiser elements and no explicit array rank. </li><li><a href="http://nemerle.org/bugs/view.php?id=582">#582</a>: Compiling "a.b.c.d.e" crashes compiler </li><li><a href="http://nemerle.org/bugs/view.php?id=583">#583</a>: Compiler crash with mixture of constructor chaining and inheritance. </li><li><a href="http://nemerle.org/bugs/view.php?id=581">#581</a>: problems with closure constructions </li><li><a href="http://nemerle.org/bugs/view.php?id=576">#576</a>: nemerle-0.9.1.99.5974: internal compiler error </li><li><a href="http://nemerle.org/bugs/view.php?id=571">#571</a>: Cast is treated as type enforcement in delayed typing </li><li><a href="http://nemerle.org/bugs/view.php?id=555">#555</a>: indexers are not delayed </li><li><a href="http://nemerle.org/bugs/view.php?id=574">#574</a>: Internal compiler error </li><li><a href="http://nemerle.org/bugs/view.php?id=565">#565</a>: No newline at the and of file causes error </li><li><a href="http://nemerle.org/bugs/view.php?id=568">#568</a>: add -stack:10M kind of option to increase the stack while running the compiler </li><li><a href="http://nemerle.org/bugs/view.php?id=536">#536</a>: assertion in Typer3 for generic local method </li><li><a href="http://nemerle.org/bugs/view.php?id=561">#561</a>: Compiler internal error when defining nested generic tree </li><li><a href="http://nemerle.org/bugs/view.php?id=527">#527</a>: nested type lookup with generic inheritance </li><li><a href="http://nemerle.org/bugs/view.php?id=563">#563</a>: Generic parameters are not correctly inherited in nested type of nested type of generic type </li><li><a href="http://nemerle.org/bugs/view.php?id=556">#556</a>: function types cannot be treated as objects </li><li><a href="http://nemerle.org/bugs/view.php?id=566">#566</a>: problem with _ is <[ _ ]> </li><li><a href="http://nemerle.org/bugs/view.php?id=567">#567</a>: unregistered value with 'with' matching </li></ul> <div align='right'><a href='http://nemerle.org/blog/archive/2006/Jan-24.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2006/Jan-24.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2006/Jan-24.html Tue, 24 Jan 2006 13:55:00 GMT 21 Dec 2005: Recent changes <h2>Yield</h2> <p> Supporting <tt>yield</tt> was harder than it first seemed. The problem was that Nemerle already supports most of the stuff needed for yield (for example putting local variables in classes so they persist), but unfortunately in a slightly different way, so a reimplementation was required in a few cases. This was very irritating (as doing the same thing twice always is). Fortunately now it works. </p> <p> There was another problem with finally blocks which has to be run only once (we don't want finally blocks to be run, when yielding a value from inside try), and also when the iterator is prematurely disposed. Fortunately C# doesn't allow yield in try-catch, so we decided to do the same ;) </p> <p> The C# spec was quite sketchy about this issue though. </p> <h2>List comprehensions</h2> <p> Haskell (as well as Python to some extent) has this really nice nice notation, that comes from math. The idea is to describe a set in terms of <i>all such <tt>x</tt> that <tt>x</tt> comes from the set <tt>A</tt> and is greater than zero</i>. This would be written as: </p> <xmp> $ [ x | x in A, x > 0 ] </xmp> <p> But this isn't really funny, so let's look at something more complicated, <i>all such pairs <tt>(x, y)</tt> that <tt>x</tt> comes from <tt>A</tt> and <tt>y</tt> comes from <tt>B</tt></i>: </p> <xmp> $ [ (x, y) | x in A, y in B ] </xmp> <p> We can now further restrict this to <tt>x < y</tt>: </p> <xmp> $ [ (x, y) | x in A, y in B, x < y ] </xmp> <p> We can even apply some complex expressions, for example to return set of lengths of elements in <tt>A</tt> we would use: </p> <xmp> $ [ x.Length | x in A ] </xmp> <p> There are functions to do all that stuff in Nemerle standard library, but list comprehensions provide a way to combine them in one short expressions. The translation of this stuff to the underling core language is straightforward -- each <tt>e in something</tt> is translated to a nested <tt>foreach</tt> loop and each condition is translated to <tt>when</tt>, details are <a href="http://nemerle.org/List_comprehensions">here</a>. </p> <p> For example to list all members in all types in all assemblies used by the program one could use: </p> <xmp> def allMembers = $[m | a in System.AppDomain.CurrentDomain.GetAssemblies (), t in a.GetTypes (), m in t.GetMembers ()]; </xmp> <p> To limit this to types from the "System" namespace we could use: </p> <xmp> def systemMembers = $[m | a in System.AppDomain.CurrentDomain.GetAssemblies (), t in a.GetTypes (), t.Namespace == "System", m in t.GetMembers ()]; </xmp> <p> And so on. Note that the following statement would have similar effect: </p> <xmp> def systemMembers = $[m | a in System.AppDomain.CurrentDomain.GetAssemblies (), t in a.GetTypes (), m in t.GetMembers (), t.Namespace == "System"]; </xmp> <p> But it would be less efficient because of calling <tt>GetMembers</tt> even for types outside <tt>System</tt>, and only discarding them later. </p> <p> This is really a nice feature and only one hour to implement :-) </p> <p> What should come next is something like: </p> <xmp> $[(x,y) | x in [1...3], y in [1,3,...,15]] </xmp> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Dec-21.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Dec-21.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Dec-21.html Wed, 21 Dec 2005 13:55:00 GMT 04 Nov 2005: Nemerle 0.9.1 is out <p> This release brings the long-awaited indentation syntax and a few bugfixes. </p> <p> About 150 SVN commits were made since the last release. </p> <h2>Availability</h2> <p> As usual we provide a source code release and a number of binary packages. Starting with this release we provide a generic Unix binary installer, similar to the one Mono has (but text-mode only). RPM and MSI packages are also ready. DEB package is on its way. </p> <h2>Language changes</h2> With the -i option compiler can now recognize indentation based syntax. More info at <a href="http://nemerle.org/Indentation-based_syntax">the wiki page</a>. <h2>Additions</h2> <ul> <li> MSBuild task.</li> <li> Marcin Grzeskowiak contributed a new matching compiler as a part of his MSc thesis. It is not yet enabled by default, as we're still testing it. You can try it with -new-matching option, but beware -- it can still contain some nasty bugs! </li> </ul> <h2>The library</h2> <ul> <li> Logging and accessor macros were improved.</li> <li> Group is now also a member of the list variant.</li> </ul> <h2> Bugfixes </h2> <ul> <li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=520">#520</a>: indentation based syntax </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=521">#521</a>: high memory usage when compiling mcs tests </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=528">#528</a>: runtime assertion failure w/respect to generics </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=530">#530</a>: antlr dll isn't compatible with mono 1.1.9 </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=531">#531</a>: Using generic method inside try-block fails to compile </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=532">#532</a>: assertion failed in file typing/Subst.n, line 184 </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=533">#533</a>: Error using quoted events </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=535">#535</a>: Double try in local function optimized to code causes error </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=537">#537</a>: Verification fails for nondesc-subseq.n </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=539">#539</a>: Failed CheckSTV with monad code </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=540">#540</a>: Using void as generic argument causes invalid IL </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=541">#541</a>: Requires macro do not work for property setter </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=542">#542</a>: Logging macros should allow various logging functions to be used (and other improvements) </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=543">#543</a>: Compiler gives internal error when trying to output into invalid directory </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=544">#544</a>: .NET do not understand 'a ---> 'b implicit conversions </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=551">#551</a>: { } brackets in string interpolation crash compiler </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=553">#553</a>: Preprocessor symbols accessible from macros API </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=554">#554</a>: Assertion about unsupported type for a complex generic hierarchy </ul> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Nov-04.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Nov-04.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Nov-04.html Fri, 04 Nov 2005 13:55:00 GMT 02 Oct 2005: The Nemerle course for OOP programmers starting on Monday <p> We'll be lunching the course tomorrow. You have the last chance to subscribe! <a href="http://nemerle.org/forum/viewtopic.php?t=9">More info...</a> </p> <p> And from the other news, I have just prepared a binary installer, much like the one mono has, for people not willing to compile. <a href="http://nemerle.org/Step_by_step_guide_to_get_Nemerle_compiler_running">Step by step guide to get Nemerle compiler running</a> has all the details. </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Oct-02.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Oct-02.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Oct-02.html Sun, 02 Oct 2005 13:55:00 GMT 14 Sep 2005: Nemerle 0.9.0 is out <h2>C# 4.0 today!</h2> <p> You read about <a href="http://download.microsoft.com/download/9/5/0/9503e33e-fde6-4aed-b5d0-ffe749822f1b/csharp%203.0%20specification.doc">C# 3.0</a> and are willing to see how could C# 4.0 look like? More powerful type inference? AST manipulation raised to its limits? Full generics support? Try Nemerle! </p> <h2>In general</h2> <p> The biggest change in this version is switch to the .NET 2.0 assemblies. The compiler now generates code using runtime generics when parametric polymorphism is used in Nemerle. While the language was designed with this switch in mind since the very beginning, the constantly changing and/or incomplete specifications forced us to make several changes to language semantics in this release. </p> <p> The intention behind the 0.9 version number is that we're now very close to the 1.0 stable release. </p> <p> We now require either Mono 1.1.9 or MS .NET Aug 2005 CTP. There are still several very serious issues with MS .NET S.R.E. API which may prevent certain features from working. Under mono there are problems with generic type serialization. </p> <p> The performance of the generic code vary. Mono folks didn't implement shared code yet, which means generic code is JITed for each instantiation. This isn't that bad as it first look though, after some tweaks that are already in the Mono 1.1.9 the performance is comparable to the non-generic version. </p> <p> In addition we should generate slightly better code overall with this version. The changes are mostly cosmetic though. </p> <p> There are some breaking changes in standard library API, because we dropped our implementation of some generic classes in favor of .NET library classes. Most previously existing classes are still available though, but they are now subtypes of their BCL counterparts. </p> <p> About 500 SVN commits was made since the last release. </p> <h2>Availability</h2> <p> As usual we provide a source code release and a number of binary packages. Starting with this release we provide a single <tt>noarch</tt> RPM package that should work with all architectures assuming mono is installed in <tt>/usr</tt>. MSI package is ready, DEB package is on its way. </p> <p> <p style="color: red"> <b>Warning:</b> Since <u><a href="http://www.timeanddate.com/worldclock/fixedtime.html?month=9&day=13&year=2005&hour=20&min=0&sec=0&p1=0">20:00 yesterday UTC</a></u> till <u><a href="http://www.timeanddate.com/worldclock/fixedtime.html?month=9&day=14&year=2005&hour=11&min=20&sec=0&p1=0">11:00 today</a></u> the 0.9.0 packages were broken. They contained a wrong version of <tt>antlr.runtime.dll</tt>. This is now fixed. </p> <p> For details consult the <a href="http://nemerle.org/Download">downloads page</a>. </p> <h2>Language changes</h2> <ul> <li> Function types are no longer covariant on return type and contravariant on argument types. While in theory it is possible to employ co/contravariant interfaces here, it doesn't work with tuple subtyping (i.e. Func[int,string,float] is subtype of Func[Tuple[int,string],float]). We have however provided implicit conversion for it, so in some cases it will still work. </li> <li> Type variables of the enclosing type are now visible in static members (in addition to instance members). This also includes nested types. This is implemented by copying type variables of the enclosing type before type variables of the nested type. If you have: <xmp class="code-csharp"> class A[X] { public class B[Y] { } public clsas C { } } </xmp> You can refer to A.B[int,string], A.C[int] as well as A[int].B[string] and A[int].C. Inside A[X] you can also refer to B[int] which means A[X].B[int] and to C which means A[X].C. </li> <li> The 'matches' keyword is no longer supported. </li> </ul> <h2>New features</h2> <ul> <li> Generic specifier -- you can specify parameters of: <ul> <li> the generic type being created: Bar.[int] ();</li> <li> the generic type some static member is accessed from: Bar[int].foo ();</li> <li> the generic method: Bar.baz.[int] ();</li> </ul> </li> <li> Missing variables in matching branches can be now specified: <xmp class="code-csharp"> match (some_list) { // treat one element list as [x, x] | [x] with y = x | [x, y] => use x and y // can also set several things at once: | [] with (x = 7, y = 12) // and mix with 'when' | [x, _, z] when x == z with y = 17 | [x, y, _] => use x and y | _ => ... } </xmp></li> <li> Partial application on steroids. In ML you could apply two argument function to a single argument and get another single argument function. We now support a similar, yet more powerful, feature: <xmp class="code-csharp"> some_fun (e1, _, e2, _) </xmp> is transformed to <xmp class="code-csharp"> fun (x, y) { some_fun (e1, x, e2, y) } </xmp> Partial application can be therefore written as 'f (x, _)'. It also works for member access: <xmp class="code-csharp"> _.foo </xmp> will be rewritten to: <xmp class="code-csharp"> fun (x) { x.foo } </xmp> The two rewrite rules can be combined -- _.foo (3, _) will result in two argument function. Note that foo (3 + _) will probably not do what's expected (it will pass a functional value to foo). Use plain lambda expression for such cases. </li> <li> Default parameters for local functions. This is mostly useful for accumulators, for example: <xmp class="code-csharp"> def rev (l, acc = []) { match (l) { | x :: xs => rev (xs, x :: acc) | [] => acc } } rev (l) // instead of rev (l, []) </xmp> as you can see the initial accumulator value is placed in a more intuitive place. Any expression is valid as a default parameter value for a local function, but beware that it is evaluated each time the function is called without this parameter. </li> <li> #pragma warning: <xmp class="code-csharp"> #pragma warning disable 10003 some_unused_function () : void {} #pragma warning restore 10003 </xmp> You can also omit warning number to disable/enable all (numbered) warnings. You can also specify several warning numbers separating them by commas.</li> <li> Special implicit blocks are created around functions and loops. After using Nemerle.Imperative; it is possible to use "break", "continue" and "return". You can supply return value to "return", much like in C. More details at the <a href="http://nemerle.org/Block">blocks page</a>. </li> </ul> <h2>Other stuff</h2> <ul> <li> Alejandro Serrano is working on Code Completion Engine, that will be used be various IDEs. For now he integrated some support for code completion in nemish (try <tt>System.Console.Wri**&lt;enter&gt;</tt>). </li> <li> Kamil Stachowski provided syntax highlighting rules for Kate.</li> <li> Language fixes in documentation courtesy of Kenneth Ismert.</li> </ul> <h2>Bugfixes</h2> <ul> <li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=156">#156</a>: Polymorphic type overloading does not work with dlls. </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=173">#173</a>: Resource Embedding </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=206">#206</a>: Apparent boxing bug in arrays </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=277">#277</a>: Switch to framework 2.0 with generics, bugfixes and so on </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=335">#335</a>: warning for $ </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=345">#345</a>: polymorphic interface method implementation checking is broken </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=348">#348</a>: Members from current type are not accessible if looked up through derived class </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=350">#350</a>: Generic and non-generic types with the same name should be different </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=354">#354</a>: Private members of class should be accessible when we are inside nested type of this class </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=359">#359</a>: Accessibility checks for protected types performed by bind_types crashes compiler </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=369">#369</a>: typed macros queue </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=381">#381</a>: Problems with casting to 'a. </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=386">#386</a>: No special where-constraints: class, struct, new () </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=388">#388</a>: type variables are not visible from nested classes </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=392">#392</a>: Null reference in generic code with ref parameters </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=417">#417</a>: Static members should be first class players in generics typing </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=423">#423</a>: the with ,,pattern'' </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=430">#430</a>: make ++/-- properly flag overflows </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=435">#435</a>: Cannot use operators by their long names </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=446">#446</a>: Container objects should show their contents </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=450">#450</a>: Futile warnings when using Glade for Gui </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=461">#461</a>: block return expression cannot be used to leave try block </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=466">#466</a>: -disable-keyword compiler flag </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=474">#474</a>: make generic specifier work </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=475">#475</a>: add `42 kind of stuff to generic types in code generation </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=476">#476</a>: handle overloaded type names in binding types </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=478">#478</a>: self calls not properly detected </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=480">#480</a>: implement polymorphic local functions generation </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=481">#481</a>: list of voids causes ice </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=482">#482</a>: bug with delayed setter property typing </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=483">#483</a>: delayed typing fails after null comparison </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=484">#484</a>: ncc wrapper not available on linux system with binfmt_misc </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=485">#485</a>: virtual or abstract methods using type parm are not overridden </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=486">#486</a>: Problems with type inference on array elements </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=487">#487</a>: Double importation of interface creates a System.NullReferenceException </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=488">#488</a>: I have no error - duplicate argument 'cx' </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=489">#489</a>: Use C#'s algorithm for searching members in classes - walking through hierarchy </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=490">#490</a>: cannot unbox system.intptr </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=491">#491</a>: Change NemerleMethod to MethodBuilder </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=492">#492</a>: Cyclic generic types causes segfault </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=493">#493</a>: Overloading fails to choose delegate when it is created implicitly </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=494">#494</a>: Elements initializing list are not properly boxed when list unifies to list[object] </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=497">#497</a>: crazy error message for incompatible types in two control flow branches </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=498">#498</a>: parsing problem with matching </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=499">#499</a>: Internal compiler error </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=500">#500</a>: Wrong name type suffix used in macros/dataNpgsql.n with mono 1.1.8.2 </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=501">#501</a>: IsRegistered failed </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=502">#502</a>: invalid IL </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=504">#504</a>: default parameters for local functions </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=505">#505</a>: Variants should be not possible to inherit </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=506">#506</a>: Enums should allow only numeric types as base </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=507">#507</a>: interfaces sometimes confuse typer in case of foreach / GetEnumerator usage </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=508">#508</a>: Property need to be marked public in order to use public get and private set </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=509">#509</a>: Usage of 'array[2, int] * int' crashes the compiler </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=510">#510</a>: unable to build 0.3.2 on OSX </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=511">#511</a>: Unable to build nemerle trunk on OSX </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=512">#512</a>: In the testsuite, positive/basic-value-types.n won't compile </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=513">#513</a>: ** ERROR **: Invalid IL code at IL0007 in _N_AutoModule:Main (): IL_0007: ret </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=514">#514</a>: true when () compiles </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=515">#515</a>: nemish prints an internal compiler error parsing a macro expansion </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=516">#516</a>: abort() doesn't work </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=517">#517</a>: nemerle fails to compile on OSX and Linux </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=519">#519</a>: Nemerle.Imperative.Return/Break </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=522">#522</a>: problem with string parsing </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=523">#523</a>: compiler throws internal compiler error typing my continuation monad </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=525">#525</a>: problem with void->object conversions in nemish </li><li><a href="http://nemerle.org/bugs/bug_view_page.php?bug_id=526">#526</a>: List literals don't work inside generic classes </li></ul> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Sep-14.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Sep-14.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Sep-14.html Wed, 14 Sep 2005 13:55:00 GMT 06 Sep 2005: Aug CTP and Mono 1.1.9, completion and forums <h2>Generics status</h2> <p> The good news is that we're able to bootstrap Nemerle compiler with both Mono SVN (thanks to Martin, no patches required anymore!) and Microsoft .NET Aug CTP. There are several limitations in their S.R.E. though, most notably we're unable to emit explicit generic interface implementations on Microsoft platform. Our <a href="http://nemerle.org/Runtime_issues">runtime issues page</a> has all the details. </p> <p> Unfortunately while MS.NET is able to run Mono produced executables (with some minor <a href="http://bugzilla.ximian.com/show_bug.cgi?id=75974">glitches</a>), Mono cannot run MS.NET produced ones (also <a href="http://bugzilla.ximian.com/show_bug.cgi?id=75973">reported</a>). Probably metadata format was changed. </p> <p> But hey! In general everything seems to go in the right direction :-) The generic specifier and nested generic types issues are now solved. I also took some time to implement wanted features (like default parameters on local functions and partial application++, #pragma warning and with-matching see <a href="http://nemerle.org/svn/nemerle/trunk/NEWS">the NEWS file</a> for details). </p> <h2>Completion engine</h2> <p> Alejandro Serrano is working since some time on C#-usable completion engine. This means it will be possible to link Nemerle.Compiler.dll to a C# application and get code completion services. This is good news for IDE integration. </p> <p> The engine is now capable of producing tree of all types and members within given set of source files (so you can say display it to the user, make it clickable (go to definition) etc). Some basic code completion is also supported, thanks to support directly in the compiler. It can now complete static and instance members as well as type names. It cannot yet deal with namespaces and local variables. </p> <p> One way or another, real IDE with completion is coming (be it #D and/or MD). </p> <h2>Forums and online course</h2> <p> We've set up a <a href="http://nemerle.org/forum/">phpBB forum</a>. It can be used for any kind of Nemerle-related communication. In particular, we would like to use it for <a href="http://nemerle.org/forum/viewtopic.php?t=9">free, online Nemerle course</a> coordination. Our <a href="http://nemerle.org/cgi-bin/cgiirc/irc.cgi">irc 2 www</a> gateway is also going to help with course communication. </p> <p> <i>Michal</i> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Sep-06.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Sep-06.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Sep-06.html Tue, 06 Sep 2005 13:55:00 GMT 08 Aug 2005: Generics branch merged into trunk <p> We have just fixed last regressions existing in generics branch and decided to move it into the main development branch. So it happened, generics are now supported on trunk. </p> <p> A short notes about current status: </p> <ul> <li>Generic parameters are not visible in nested types, but they are visible in static members of current class <a href="http://nemerle.org/bugs/view.php?id=388">#388</a>. </li> <li>Generic specifier (the ugly <tt>def x = NotInferredClass .[string, int] ();</tt> syntax) works in most cases (methods and constructors), I guess it could have some problems in more complex cases (malekith knows the details) <a href="http://nemerle.org/bugs/view.php?id=474">#474</a>. </li> <li>We do not report errors for incorrect use of special constraints <a href="http://nemerle.org/bugs/view.php?id=386">#386</a>.</li> <li>We are aware of the error situation, which can arise from a very sick self tail call <a href="http://nemerle.org/bugs/view.php?id=478">#478</a>. </li> </ul> <p> Other problems with generics should be reported as bugs - in general we would like to support all scenarios you could use in C# and much more (especially in case of type inference). </p> <p> Short list of features: </p> <ul> <li>All built-in data-structures are now using generics (functional objects, tuples, lists). </li> <li> Most collections from Nemerle.Collections are now subtypes of .NET equivalents, but adding some new methods like Iter and Map for easier usage with functional objects. They also provide ToString override, which prints out their contents. </li> <li> All ugly bugs with arrays vs generics simulation has been fixed and forgotten. </li> <li> <p> Type inference is very powerful in guessing the types of generic structures, if it can't it use object by default (you can use generic specifier or in some cases type enforcement to specify exact type parameters). </p> <p> Stuff like below works perfectly, is typesafe and require not casts. </p> <xmp class="code-csharp"> using System.Collections.Generic; def dict = Dictionary (); dict.Add (1, "travel"); dict.Add (2, "time"); assert (dict [1] == "travel"); </xmp> </li> <li> Nemerle collections can be used from C# without problems (we generate types, which are in the same format as C# compiler use). </li> <li> After a few patches for mono from malekith, the performance is almost the same as the compiler version without generics. </li> </ul> <p> The bad news is that we were unable to get compiler working on MS.NET 2.0 (neither Beta 2 nor July CTP). There are numerous bugs, which we regularly report and sometimes manage to workaround. Currently building Nemerle.dll causes various exception stack traces in runtime, but when we copy it from boot/ then rest of the compiler builds fine. So you won't be able to use trunk with MS.NET until (hopefully) the next public release (I guess in September). Also with mono, you will need to use svn version (AFAIK the 1.1.9 release is not going out very soon, but probably it is a matter of month). Sorry for inconvenience. </p> <p> For anybody, who is unable to run trunk version we have branched out the non-generic version into </p> <tt>http://nemerle.org/svn/nemerle/branches/nongeneric</tt> <p> you can also stay with trunk revision 5546 </p> <tt> svn up -r 5546 http://nemerle.org/svn/nemerle/trunk </tt> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Aug-08.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Aug-08.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Aug-08.html Mon, 08 Aug 2005 13:55:00 GMT 01 Jul 2005: It boots! <p> After exactly a month, since <a href="http://nemerle.org/mailman/pipermail/svn/2005-June/005190.html">we have created</a> generics branch, the Nemerle compiler finally can compile itself generating working generic code. It was harder than we initially thought due to numerous issues in both Mono and MS.NET runtimes. Mono had more issues, but the feedback loop was much shorter, Martin was very quick to fix problems we have found, thank you! <a href="http://bugzilla.ximian.com/show_bug.cgi?id=75429">#75429</a> was the last one preventing full bootstrap. </p> <p> I was somewhat disappointed by poor performance of the generic code. Nemerle uses a lot of generic containers and switching from cast-everything-to-object (type erasure) to real generic code brought us about 10x slowdown. On small example (the standard library) the non-generic code uses 6.4s vs 50s, on a larger one (the main compiler library) it is 41s vs 405s. This is all on amd64 (1.8Ghz). </p> <p> We will be doing some micro benchmarks shortly, but as I understand it today mono creates a separate copy of machine code for each instantiation of generic type or generic method. Which seems to be a problem with heavily polymorphic code, like the one we use. </p> <p> But hey, it works! :-) </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Jul-01.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Jul-01.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Jul-01.html Fri, 01 Jul 2005 13:55:00 GMT 01 Jun 2005: Nemerle 0.3.2 released! <p> This version brings a few new features and a bunch of bugfixes. About 350 svn commits was made to the svn repository since the last release. </p> <p> New features:</p> <ul> <li>You can now omit prefixes of variants and enums in matching, for example: <xmp class="code-csharp"> variant Foo { | A | B } match (some_foo) { | A => ... | B => ... } enum Bar { | A | B } match (some_bar) { | A => ... | B => ... } </xmp> The restriction is that the type of <tt>some_foo</tt> need to be statically known to be <tt>Foo</tt>. If type inference cannot guess it at this point, you will have to match over <tt>(some_foo : Foo)</tt> or specify <tt>Foo.A</tt> in the first branch. Same goes to Bar. This feature is similar to switches on enums in Java 5.0. </li> <li>Default parameters: <xmp class="code-csharp"> public DoFoo (s : string, flag1 : bool = true, flag2 : bool = false) : void { } </xmp> For boolean, integer and string default value the type of parameter can be omitted: <xmp class="code-csharp"> public DoFoo (s : string, flag1 = true, flag2 = false) : void </xmp> Only other allowed default value is null: <xmp class="code-csharp"> public DoFoo (x : SomeClass = null) : void </xmp> </li> <li>The warning that you should use <tt>FooBar where (...)</tt> instead of plain <tt>(...)</tt> is gone. We have found that it was a mistake.</li> <li>Blocks, it is possible to construct a block you can jump out of with a value. For example: <xmp class="code-csharp"> def has_negative = res: { foreach (x in collection) when (x < 0) res (true); false } </xmp> Please consult <a href="http://nemerle.org/Blocks">Blocks</a> for details. </li> <li>Tuples can be now indexed with []. It is only supported with constant integer indexes. Indexing starts at 0, so <tt>pair[1]</tt> is <tt>Pair.Second (pair)</tt></li> <li>Nemerle.English namespace now contains <b>and</b>, <b>or</b> and <b>not</b> logical operators</li> <li>Macros can now define textual infix and prefix operators (just like <b>and</b> above)</li> <li>Number literal can now contain _ for readability, for example <tt>def x = 1_000_000;</tt></li> <li> <a href="http://nemerle.org/Lazy_evaluation">Lazy value</a> macros</li> <li>Automatic <a href="http://nemerle.org/Accessor_macros">get/set accessor generation</a> macros</li> <li>mutable can now define more than one variable: <xmp class="code-csharp"> mutable (x, y) = (42, "kopytko"); x++; y = "ble"; mutable x = 3, y = "kopytko"; // the same </xmp> The second version does not work inside <tt>for (here;;)</tt></li> <li>Arrays are no longer covariant. They haven't been in 0.2 days, and we have found it to be causing problems with type inference (see <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=442">#442</a>)</li> <li>Tuples and lists are now serializable. Variants are deserialized properly</li> <li>Code can be entered at the top level, without a class and the Main method. So the classic example becomes:</li> <xmp class="code-csharp"> System.Console.Write ("Hello marry world!\n"); </xmp> That is, it put alone in the file will just compile. You can define classes, issue using declarations before the actual code. You can also define local functions with def (which gives you type inference). Yeah, we know this is only useful in write-once-run-once-throw-away kind of programs and testing, but it is nice anyway :-) </li> <li>The CExpr compiler stage has been removed, which means that a/ we are more likely to implement generics soon, b/ we generate better code overall. Especially matching has been benchmarked and improved. </li> </li> </p> <p> Fixed bugs from our <a href="http://nemerle.org/bugs/">bugtracker</a>: </p> <ul> <li> Overload selection rules have been improved, especially in presence of var args, parametric types and named parameters.</li> <li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=142">#142</a>: default parameters </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=303">#303</a>: indexing operator on tuples </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=351">#351</a>: Assigning to generic type's field does not yield its type's argument specialization </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=387">#387</a>: Exhaustiveness check of tuple patterns with variants is exponential </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=401">#401</a>: cannot define macros on assembly </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=408">#408</a>: Do not create delegate proxy for instance methods </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=409">#409</a>: Omitting the prefix when matching variants </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=410">#410</a>: overload selection rules </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=419">#419</a>: Logic operands in plain English </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=422">#422</a>: _ in number literals </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=426">#426</a>: macros assigned to local identifiers </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=428">#428</a>: macros for lazy values </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=434">#434</a>: /*\n Hang emacs </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=437">#437</a>: Define more than one variable in the for( ; ; ) construct - extend mutable definition </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=438">#438</a>: Destroy CExpr stage </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=440">#440</a>: bogus error messages about meanings of the module </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=442">#442</a>: code generated for arrays forgets inferred type and crashes </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=443">#443</a>: Wrong computation order when assigning the return value of a function to a field during field declaration </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=444">#444</a>: assertion in Typer2 when ignoring value </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=445">#445</a>: delayed typings does not work on lhs of = </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=447">#447</a>: Closurising caught value causes invalid IL </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=449">#449</a>: implementing interfaces vs object subtyping </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=451">#451</a>: -r:Nemerle.Compiler.dll </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=453">#453</a>: Tuples are not serializable </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=454">#454</a>: the ::= operator </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=455">#455</a>: no warning for uninitialized members of struct </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=456">#456</a>: Trying to escape block label crashes compiler </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=457">#457</a>: Optional macro syntax extension not working </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=458">#458</a>: Nemish fails to load profile. </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=459">#459</a>: windows ncc.exe Url error </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=463">#463</a>: matching compiler should use gotos not switches </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=464">#464</a>: serialization and singleton pattern for variant options </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=465">#465</a>: Unable to infer common type when there is also common interface </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=467">#467</a>: get rid of TExpr.TailCall </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=469">#469</a>: DecisionBuilder crashes on counterexample building </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=470">#470</a>: inference for default parameters </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=471">#471</a>: type inference does not work for enforcements </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=472">#472</a>: preprocessor directive handling broken </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=473">#473</a>: _ shouldn't be allowed in global types </ul> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Jun-01.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Jun-01.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Jun-01.html Wed, 01 Jun 2005 13:55:00 GMT 02 May 2005: Nemerle 0.3.1 released! <p> This version is a quick fix for issues reported with the 0.3.0 release. </p> <p> Bugfixes:</p> <ul> <li> The MSI package now have the proper version of cs2n. </li> <li> The issues with loading external enums based on the long type are be fixed now.</li> <li> Emacs mode should no longer hang on comment edition (<a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=434">#434</a>).</li> <li> There are quite a few language fixes in the documentation, thanks to Andy Burns and other nameless documentation updaters.</li> </ul> <p> There is a single nice feature that sneaked into this release, it is now possible to match inside the foreach loop directly (<a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=436">#436</a>), that is: <xmp>foreach (op in ops) { | Op.A => ... | Op.B => ... } </xmp> will now work as: <xmp>foreach (op in ops) { match (op) { | Op.A => ... | Op.B => ... } } </xmp> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/May-02.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/May-02.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/May-02.html Mon, 02 May 2005 13:55:00 GMT 29 Apr 2005: Nemerle 0.3.0 released! <p> This is the long awaited second milestone release (after 0.2.0 -- CLS consumer) with a new typing engine and a new parser. </p> <p> About 300 svn commits has been made since the last release. </p> <p> Additions: </p> <ul> <li> The most important addition in this release are implicit conversions of several kinds. <ul> <li> We now respect user-defined <tt>op_Implicit</tt> (like the ones for Decimal type) </li><li> Functional values are implicitly converted to delegates. </li><li> <tt>when (...) 3;</tt> now gives a warning instead of error (about using implicit <tt>object -&gt; void</tt> conversion). </li><li> Last but not least, conversions are provided for built-in numeric types like int and long. They work much <a href="http://www.c-sharpcorner.com/Language/TypeConversionsInCSharpRVS.asp">like in C#</a>. This also works in a kinda special way for literals. There might be some related bugs with constant folding though.</li> </ul> </li><li> From the cute new features departments -- it is now possible to use pattern matching on properties, in addition to previous possibility of matching on fields. </li><li> Another nice addition are the P/Invoke methods. </li><li> The interactive interpreter -- nemerlish -- has been included in the default build and install. </li><li> Indentation engine in the emacs mode has been improved. </li><li> 'is' can be now used where 'matches' was. 'matches' shall be considered obsolete by now. It will give a warning in the next release. <br/> There is one drawback with this change. If you have been using a polymorphic variant (like <tt>x is Some</tt>) on the right hand side of 'matches' it won't work anymore. You either need to supply the type argument (<tt>x is Some [int]</tt>), you can use wildcard type (<tt>x is Some [_]</tt>), or make it a valid non-identifier pattern (<tt>x is Some (_), x is None ()</tt>).<br/> For the particular Some/None you can use freshly added <tt>IsSome/IsNone</tt> properties. </li> </ul> </ul> <p> Incompatible changes: </p> <ul><li> The arithmetic operators on types smaller than int now return int. This is the same behavior as in C (and C#). </li><li> Various matching optimization flags have been removed (they now print a warning). Boolean optimizations are now always enabled, while the other were buggy. Patches are welcome. </li><li> Progress bar is now disabled by default. You -bar+ switch to turn it on (we found people very often disable it, and it confuses emacs).</li></ul> <p> Library:</p> <ul><li> List manipulation functions have been added to the list type itself. Bugfixes: </li><li> The MSI package now properly installs itself in the directory specified, not always in "c:/Program Files/Nemerle/".</li> </ul> <p> Fixed bugs from our <a href="http://nemerle.org/bugs/">bugtracker</a>: </p> <ul><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=007">#007</a>: Static variable initalization in metadata </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=119">#119</a>: subtyping relation for numeric types </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=138">#138</a>: matching on properties </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=249">#249</a>: functions are not "boxed" to delegates </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=256">#256</a>: Should we implicitly convert from DateTime to SqlDateTime </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=284">#284</a>: a=b-1U; does not parse </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=316">#316</a>: Allow PInvoke methods </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=334">#334</a>: Custom operators are not looked up properly </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=343">#343</a>: Algorithm for binding base classes is broken </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=360">#360</a>: Inference engine loops compiler when parameter is used on itself as function </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=364">#364</a>: support ++/-- overloads </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=383">#383</a>: Assigning to variable with name of type </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=390">#390</a>: Problems with the $-notation </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=391">#391</a>: Explicit cast operator is not chosen when needed </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=393">#393</a>: Using nested foreach crashes compiler. </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=394">#394</a>: We do not check attribute targets </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=395">#395</a>: Another meaningless error message </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=396">#396</a>: ncc crashes during typing of foreach loop on N.C.Hashtable </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=397">#397</a>: ICE when fixing type of local function </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=398">#398</a>: return type is not checked in delayed overloads </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=399">#399</a>: comparing with == against null shall not be special </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=400">#400</a>: strange problem with delayed typings and overload resolution </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=402">#402</a>: cannot use _ in keywords </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=404">#404</a>: $ "$Name" doesn't work -- usesite problems </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=406">#406</a>: Something is broken with expected return types </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=407">#407</a>: Lambdas from embedded expressions crashes compiler </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=414">#414</a>: comparing ,,result'' of mutable definition to null causes ICE </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=418">#418</a>: Literal fields should be available in match patterns </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=420">#420</a>: Nested types are not visible in derived class </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=421">#421</a>: Add implicit conversion from 0 to any enum </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=424">#424</a>: merge the literals branch </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=431">#431</a>: Change 'matches' to 'is' </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=432">#432</a>: ice with foo(){| _ =&gt; {}} </li></ul> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Apr-29.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Apr-29.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Apr-29.html Fri, 29 Apr 2005 13:55:00 GMT 24 Apr 2005: Generics progress <p> I have been experimenting with adding generics support in Nemerle code emission engine. One could think that this should be an easy task in compiler already having parametric polymorphism. This is partially true, I don't have to touch typing engine too much, most of the information is already there. But on the other hand, there are still some blocking issues inside the compiler (informations which are not stored in program tree, because they were not used till now), and what is much more pain, in .NET frameworks we are using. </p> <p> People are quite excited with lately released VS 2005 Beta2, but from the compiler perspective it doesn't bring too much. Literally all the bugs we have <a href="http://nemerle.org/Runtime_issues">reported</a> all over the last half year are still not fixed. That's ok, frameworks have bugs, in many they cases can be workarounded. But when we talk about generics... well, would you expect <em>ToString</em> or <em>Equals</em> methods to throw <em>NotSupportedException</em>? This is why I finally decided to move my experiments to Mono. </p> <p> Of course live isn't easy here too. First I had to write methods recently added in MS.NET Beta2 in Mono BCL (unfortunately they are just quick hacks for my experiments, I didn't dig into mono S.R.E internals to create fully functional implementation). They are used to obtain members from instantiated generic type basing on member builders coming from noninstantiated type. For example consider </p> <xmp class="code-csharp"> class G ['a] { public this (x : 'a) { } public foo (x : 'a) : list ['a] { } } ... def x = G (1); x.foo (2); </xmp> <p> During compilation we have <em>TypeBuilder</em> representing <em>G</em> and <em>MethodBuilder</em> representing <em>foo</em>, we then want to obtain <em>MethodInfo</em> for <em>G [int].foo</em>, so we use <em>TypeBuilder.GetMethod (instanciated, foo_method_builder)</em>. And with this thing everything seemed to go right with Mono, until I came into <a href="http://bugzilla.ximian.com/show_bug.cgi?id=74684">this</a>. Well, I hope this won't be hard to fix, now I must deal with other issues inside Nemerle compiler anyways. </p> <p> Summarizing, the smell of "fresh stuff" is still near generics in .NET, especially when we come into S.R.Emit API. But even with these issues I was able to make some progress. My <a href="http://nemerle.org/svn/nemerle/trunk/ncc/testsuite/todo/generics.n">current play-field</a> already contains interesting stuff. Especially we can observe immediate advantage of using Nemerle type inference in working generic code like </p> <xmp class="code-csharp"> def x = System.Collections.Generic.List (); x.Add ("Bla"); assert (x[0] == "Bla"); </xmp> <p> compared to C#'s </p> <xmp class="code-csharp"> System.Collections.Generic.List<string> x = System.Collections.Generic.List <string> (); x.Add ("Bla"); assert (x[0] == "Bla"); </xmp> <p> Time will show how my experiment will progress into fully working solution. There is much chance that Nemerle will be the first bootstrapping compiler extensively using S.R.Emit to generate and utilize generics in the world (AFAIK gmcs isn't using generics for its own bootstrap). </p> <p> BTW: We have a little <a href="http://nemerle.org/phpESP/public/survey.php?name=poll2">Language Poll</a>. Please stop by and give us some feedback about the tricky design decisions. </p> <p><i>--Kamil</i> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Apr-24.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Apr-24.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Apr-24.html Sun, 24 Apr 2005 13:55:00 GMT 06 Apr 2005: New web site <p> We've been quite busy lately migrating content from our old XML-generated <a href="http://nemerle.org/">webpage</a> to a wiki solution. It is using <a href="http://mediawiki.org/">Media Wiki</a> (yeah, the same as in wikipedia and mono-project sites). It seems to work quite well. </p> <p> The silent hope behind this idea is to make it easier to publish some learning materials about Nemerle and fix/extend the existing, so external contributors can do it. </p> <p> One of my personal fears was that it is going to be inefficient. Fortunately with <a href="http://eaccelerator.sourceforge.net/">eAccelarator</a> it seems to work quite well (it can now handle about 15 hits per second which is well above the typical /. attack level :-). </p> <p> Another thing was the inability to make a hard copy of several related pages, like some bigger tutorials. However after little perl voodoo we rip the content from the wiki to HTML, later to TeX and finally to <a href="http://nemerle.org/Static_Copy">PDF</a>. </p> <p> One thing remains to be moved -- it's the language reference manual. It contains grammar description which I have no idea how to put into the wiki... (other than simply putting it in &lt;pre&gt;). </p> <p><i>--Michal</i> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Apr-06.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Apr-06.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Apr-06.html Wed, 06 Apr 2005 13:55:00 GMT 31 Mar 2005: Nemerle 0.2.10 released! <p> This is another preview before 0.3.0. We have fixed a handful of bugs and decided to give it another shot. </p> <p> About 100 svn commits has been made since the last release. </p> <p> Additions: <ul> <li> There is Nemerle NAnt task included in the distribution. </li><li> The XSP (ASP.NET) integration has been tested and documented, please refer to <a href="http://nemerle.org/wiki/ASP.NET">wiki page about it</a>. </li><li> We do not support binary installation from tarball -- bootstrap is now always required. </li> </ul> </p> <p> <ul> <li> A Nemerle syntax file genShi has been added to the distribution and is now used in our Wiki for colorizing sources. </li><li> Tests are now run using Nemerle.Compiler.dll as a library -- it is a lot faster. </li><li> We now support Windows style <tt>/options</tt>. </li><li> New <tt>/greedy-</tt> option to disable recursive loading of assemblies. </li><li> Yet incomplete support for <tt>new()</tt>, <tt>class()</tt> and <tt>struct()</tt> generic constraints. </li> </ul> </p> <p> Bugfixes: <ul> <li> The SQL macros should now compile fine. </li><li> We now support creation of delegates from external static functions. </li><li> Installation issues with and without antlr should be now resolved. </li><li> Error message involving types and custom attributes should be better now. </li><li> Quotations in response files are handled properly now. </li><li> Documentation updates. </li><li> Snapshots/SVN now use <tt>*</tt> as last part of assembly version, which should cure all already-installed-to-the-GAC build problems. </li><li> We treated <tt>type[]</tt> as a generic type with no arguments. This is fixed now. </li> </ul> </p> <p> Fixed bugs from our <a href="http://nemerle.org/bugs/">bugtracker</a>: <ul> <li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=302">#302</a>: there should be nemerle.pc file </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=334">#334</a>: Custom operators are not looked up properly (there is still some issues here) </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=340">#340</a>: Enum options with lowercase name are wrongly understood in patterns </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=362">#362</a>: access rights are not checked for property accessors </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=372">#372</a>: Typer crashes when match results are first System.Enum then null (matching enum values) </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=375">#375</a>: ice in null pattern exhaustiveness check </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=377">#377</a>: wrong error message for accessing instance from another class </li><li> <a href="http://nemerle.org/bugs/bug_view_advanced_page.php?bug_id=380">#380</a>: nemerle from MSI package have problems with loading Nemerle.Macros properly [<font face="red">a killer bug</a>] </li> </ul> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Mar-31.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Mar-31.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Mar-31.html Thu, 31 Mar 2005 13:55:00 GMT 22 Mar 2005: Nemerle 0.2.9 released! <p> This is preview release before 0.3.0, which is real soon now. There are lots of changes in this version -- the parser and the typer (which constitute more then half of the compiler) have been replaced by entirely new implementations. </p> <p> There is a number of backward incompatible changes in this release. Most of them were previously discussed on the mailing list, and received rather good feedback other only generate warnings in this release. We apologize for both. We hope they make Nemerle a better language. On the plus side -- we should be now far closer to certain language stabilization point. </p> <p> 0.3.0 should bring implicit conversions, List iterators as list[T] methods and maybe some more goodies. </p> <p> Incompatible language changes:<ul> <li>Variant options are now nested inside enclosing variant, so their names need to be prefixed with variant name. For example: <xmp class="code-csharp"> variant Foo { | A | B { x : int; } } ... def x = Foo.A (); match (some_foo) { | Foo.B (3) =&gt; ... | _ =&gt; ... } </xmp> You can mark variant with <tt>[ExternallyVisibleOptions]</tt> to import its options outside the variant or open variant name with <tt>using</tt>. More details in <a href="http://nemerle.org/mailman/pipermail/devel-en/2004-September/000256.html">this thread</a>. </li><li>Generic types use now [] instead of &lt;&gt;. That is there is <tt>list [int]</tt> not <tt>list &lt;int&gt;</tt>. This is the second (and hopefuly last ;-) time we change it. More details in <a href="http://nemerle.org/mailman/pipermail/devel-en/2004-September/000259.html">this thread</a>. </li><li>Record patterns like <tt>{ foo = 42; bar = 3 }</tt> are now deprecated. New <b>where</b> patterns have been introduced, to explicitly mark the class used for matching: <xmp class="code-csharp"> | Foo.Bar where (x = 3, y = Qux) =&gt; ... | Foo.Bar where (3, Qux) =&gt; ... </xmp> Variant patterns now also support field names: <xmp class="code-csharp"> | Deep.Though (x = 7) =&gt; ... </xmp> </li><li>The <b>:</b> operator in patterns should from now on be only used to statically enforce type. Runtime type checks should be performed with the <tt>is</tt> operator which uses the same syntax: <xmp class="code-csharp"> match (some_list) { | (x : int) :: xs =&gt; OverloadedFunction (x); loop (xs) | [] =&gt; {} } match (some_expr) { | x is Foo =&gt; ... | x is Bar =&gt; ... | _ =&gt; ... } </xmp> Trying to use <tt>:</tt> or <tt>is</tt> in the other context will rise warning. It will be hard error for <tt>:</tt> used as <tt>is</tt> in future release. </li><li>The catch handler syntax has been changed to reflect change in matching: <xmp class="code-csharp"> try { ... } catch { | foo is SomeException =&gt; ... | bar is Exception =&gt; ... // or | bar =&gt; ... // or | _ =&gt; ... } </xmp> </li><li>Macros can no longer be nested in classes</li> </ul> </p> <p> Language additions:<ul> <li>Added &lt;&lt;, &gt;&gt;, |, ^ and &amp; operators. %|, %^ and %&amp; remain there. </li><li>It is now possible to ignore values like this: <xmp class="code-csharp"> _ = ignore_me (17); </xmp> </li><li>It is now possible to assign stuff to tuples, like this: <xmp class="code-csharp"> mutable x = 7; mutable y = "foo"; (x, y) = (42, "bar"); </xmp> </li><li>Function parameters can be now marked <tt>mutable</tt>. </li><li>The <tt>partial</tt> modifier on classes is now supported. </li><li><tt>{ def _ = foo; }</tt> is now allowed without the additional <tt>()</tt> at the end. </li><li>New <tt>throw;</tt> expression to rethrow the exception. </li><li>The type inference engine has been replaced by a new one: <ul> </li><li>code like this compiles fine: <xmp class="code-csharp"> def foo (x) { x.bar () } List.Map (some_list, foo) </xmp> when the type of <tt>some_list</tt> is known. </li><li>overloading resolution now works when passing functional values: <xmp class="code-csharp"> List.Sort (some_list, string.Compare) </xmp> </li><li>variant option's constructors have now proper type, that is there is no longer need to <tt>SomeVariant.Option () :&gt; SomeVariant.Option</tt> </li><li>stuff like <tt>array [A (), B ()]</tt> should now work (if <tt>A</tt> and <tt>B</tt> have a common supertype)</li> </ul> </li><li>Add <tt>repeat (times) body</tt> language construct</li> </ul> </p> <p> Library changes:<ul> <li>IMap.Fold used to use reverse parameter order then other fold functions. It is fixed now. </li><li>A new Set class has been added. </li><li>Nemerle.Collections.Vector is now enumerable (patch by nuffer). </li><li>New functions in List:<ul> <li>MapFromArray </li><li>GetElementType </li><li>Contains </li><li>ContainsRef </li><li>FirstN </li><li>ToString (separator : string)</li> </ul> </li><li>List <tt>Length()</tt> and <tt>IsEmpty()</tt> are now properties. </li><li>New functions in Option:<ul> <li> Iter</li> <li> GetHashCode override </li> </ul> </li><li>Stack.Top() is now a read/write property.</li> </ul> </p> <p> Macro library changes:<ul> <li>Concurrency macros based on implementation of Polyphonic C# has been added (implemented by Ricardo). </li><li>The foreach macro now uses semantics consistent with matching: foreach (s : string in foo) requires elements of foo to be of statically known type string, foreach (s :&gt; string in foo) casts each element of foo to string (raising exception in case of problems) and foreach (s is string in foo) executes the loop body only for strings in foo. </li><li>Assertions macros now have new syntax extensions available. They can be used like in http://nemerle.org/macrouse.html#designbycontract </li><li>Added macro library for type-safe SQL operations with MS SQL Server </li><li>Diagnostics macros now have parameterless Trace macro and <tt>time</tt> macro for measuring performance of some chunk of code </li><li>Quotations of patterns, types and expressions are now unified to simple use of <tt>&lt;[ some code ]&gt;</tt> </li><li>Added OverrideObjectEquals macro for automating overriding of Equals (object) method with type-safe Equals (SomeType) method</li> </ul></p> <p> Other stuff:<ul> <li>Parser has been changed, it gives better error recovery, forward lookup and capability of deferring parsing in syntax extensions (see <a href="http://nemerle.org/mailman/pipermail/devel-en/2005-March/000427.html">here</a>) </li><li>We have a new tool -- a C# to Nemerle converter. It produces human-readable Nemerle sources. </li><li>We have added over 300 converted testcases from MCS. ncc behaves now far more sane and C#-like especially at the class level. </li><li>The -doc switch can be now used with <a href="http://ndoc.sf.net/">NDoc</a>. Example output can be seen <a href="http://nemerle.org/doc/">here</a>. </li><li>Some warnings can be now disabled by-number, there is also -warn warning level switch. </li><li>Simple Nemerle interactive shell has been included in the distribution. </li><li>The debug symbol output should work under MS.NET. </li><li>The Sioux webserver has been greatly extended. </li><li>A syntax highlighting file for Midnight Commander editor. </li><li>The htmldumper tool has been written -- it creates pretty Nemerle sources for the web. </li><li>It should be now easier to compile Nemerle on Windows using MinGW. </li><li>Lots of performance work -- in the compiler, the library and the generated code. </li><li>Lots of bugs hunted.</li></ul></p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Mar-22.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Mar-22.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Mar-22.html Tue, 22 Mar 2005 13:55:00 GMT 13 Mar 2005: Intersection types <p> This is RFC. There is a problem with new type inference engine and intersection types. Or maybe intersection types in general. But, from the beginning. </p> <p> The type inference algorithm works by assigning type variables, that are yet-uninitialized types, to various parts of the program and trying to deduce something about the type of the program. For example: </p> <xmp class="code-csharp"> class C { static foo (x : int) : string { ... } static bar[T] (x : T) : list[T] { ... } static Main () : void { def x = 3; // easy, x has type int def y = foo (x); // again easy, y has type string def z = bar (y); // harder -- z has type list[type_of y], // so it has type list[string] ... } } </xmp> <p> Now consider lists: </p> <xmp class="code-csharp"> class list {...} class Cons : list {...} // head and tail class Nil : list {...} // empty list </xmp> <p> This is mostly how the lists look in Nemerle -- two subclasses of a <tt>list</tt> class. Now, let's have a look at how the list is constructed (the <tt>new</tt> keyword is skipped in Nemerle): </p> <xmp class="code-csharp"> def empty = Nil (); def my_list = Cons (some_elem, empty); </xmp> <p> There is no problem -- <tt>empty</tt> gets type <tt>Nil</tt> and <tt>Cons</tt> takes <tt>list</tt> as a second argument. But <tt>Nil</tt> is subtype of <tt>list</tt>, so the call to the <tt>Cons</tt> constructor is happily typed, and <tt>my_list</tt> gets type </tt>Cons</tt>. </p> <p> But lets tell, we want to reuse variable first for empty list, and then for a non-empty one: </p> <xmp class="code-csharp"> mutable the_list = Nil (); the_list = Cons (some_elem, the_list); </xmp> <p> In the first line <tt>the_list</tt> gets type <tt>Nil</tt>. Now in the second line, the call to <tt>Cons</tt> is typed without a problem, like in the previous example. However it results in <tt>Cons</tt> type. And type <tt>Cons</tt> cannot be assigned to a cell of type <tt>Nil</tt>. The code like the above is quite common in Nemerle -- the syntax a little bit different: </p> <xmp class="code-csharp"> mutable the_list = []; the_list = some_elem :: the_list; </xmp> <p> But the meaning is the same. What can the user do is to explicitly upcast <tt>the_list</tt> to type <tt>list</tt> and everything is OK. But upcasts are supposed to be automatic. The previous inference algorithm had an hack here -- the constructors <tt>Cons</tt> and <tt>Nil</tt> had type <tt>list</tt>, so the upcast wasn't needed. But we sometimes want to use full <tt>Cons</tt> type, not the poorer <tt>list</tt> version. Therefore the new algorithm was supposed to lift this restriction, and do something about it. </p> <p> The actual solution is to assign a special type <tt>at-most-Nil</tt> to <tt>the_list</tt>. Then, upon assignment, the type is changed to biggest common supertype of <tt>Nil</tt> and <tt>Cons</tt>, that is <tt>list</tt>. And everyone is happy -- we can use <tt>Nil()</tt> with its full <tt>Nil</tt> type and assignments work OK. </p> <p> However there is a problem. Consider: </p> <xmp class="code-csharp"> mutable x = 3; x = "string"; </xmp> <p> First off, this is most likely a bug. If the smallest common supertype of <tt>string</tt> and <tt>int</tt> were <tt>object</tt> it wouldn't be that big of a problem -- even now we just forbid two types, different than the <tt>object</tt> itself, to sum up to <tt>object</tt> -- because it is a bug in more than 50% of cases. However beside <tt>object</tt> they share three interfaces (<tt>IComparable, IFormattable, IConvertible</tt>). So the smallest common supertype of <tt>int</tt> and <tt>string</tt> is <b>intersection</b> of types <tt>IComparable, IFormattable</tt> and <tt>IConvertible</tt>. This is how NTE currently handles it. But we clearly (?) don't want this intersection type here. We want an error message. </p> <p> So now the RFC -- my idea was to drop this beautiful intersection types -- that is if we want to sum up two types that have more than one most specific common supertype (like in the case above) -- to bomb out with an error. This is what constraint solver in Generic Java does. Generic C# doesn't have any constraint solver I'm aware of. The example with list would still work of course. </p> <p> <i>-- Michal</i> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Mar-13.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Mar-13.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Mar-13.html Sun, 13 Mar 2005 13:55:00 GMT 06 Mar 2005: Dots, vlists and matching <p> If you want my advice -- never write a metric truck load of code to debug it later. I'm still trying to debug the new type inference engine I wrote. 18 out of 60 dots of <tt>Nemerle.Compiler.dll</tt> are eaten :-) (ncc displays progress bar consisting of dots, that are replaced by underscores). This is getting annoying. </p> <p> But, from the good news, some time ago we were discussing idea of adding new stuff to existing library classes. For example you have the <tt>System.String</tt> class and want the <tt>Nemerle.Utility.NString.Split</tt> static method, that works on lists and not on arrays, to be one of the regular <tt>String.Split</tt> overloads. We're not interested in really extending the class -- some syntactic sugar should be enough. </p> <p> This seems doable, it is still in the design stage. The idea come back when I read <a href="http://sourceforge.net/mailarchive/forum.php?thread_id=6740097&forum_id=29880">this discussion</a> on the ocaml-lib-devel mailing list. It was about the implementation of the <a href="http://icwww.epfl.ch/publications/documents/IC_TECH_REPORT_200244.pdf">VList data structure</a>, that is another storage architecture for immutable ML-like lists. The benchmarks are quite promising -- it is much faster than the regular list for most operations. And taking into account that OCaml has a very good, precise garbage collector -- it gets even more interesting. </p> <p> So the idea was to replace regular lists in Nemerle with vlists, and see what happens. Converting lists constructors isn't very hard, just a small compiler hack. The hard part is matching. Matching on lists in Nemerle looks like this (you can use the <tt>::</tt> syntactic sugar that is really used in the sources in comments): </p> <xmp class="code-csharp"> match (some_list) { | list.Cons (x, xs) => // x :: xs do_something_for_head (x); do_something_for_the_rest_of_the_list (xs); | list.Nil => // [] do_something_else () } </xmp> <p> while the list data type definition looks like this: </p> <xmp class="code-csharp"> variant list [T] { | Cons { head : T; tail : list [T]; } | Nil } </xmp> <p> So the idea Kamil and I come up to was to annotate VList like this: </p> <xmp class="code-csharp"> class VList [T] { public enum State { | Cons | Nil } [MatchOnThis] public TheState : State { get { ... } } [FieldInOption ("Cons")] public Head : T { get { ... } } [FieldInOption ("Cons")] public Tail : VList [T] { get { ... } } // the real implementation of vlists... } </xmp> <p> The <tt>[MatchOnThis]</tt> macro would produce <tt>VList.Cons</tt> and <tt>VList.Nil</tt> bogus members, while the <tt>[FieldInOption]</tt> macros would add specific members to them. So the macthing like: </p> <xmp class="code-csharp"> match (some_list) { | VList.Cons (x, xs) => do_something_for_head (x); do_something_for_the_rest_of_the_list (xs); | VList.Nil => do_something_else () } </xmp> <p> would be possible. What would remain then would be changing the builtin <tt>[...]</tt> and <tt>::</tt> literals to reference <tt>VList</tt> instead of <tt>list</tt>. </p> <p> The idea is somehow broader. For example we could add matching to XML elements this way. Now we need the extending-existing-class part. </p> <xmp class="code-csharp"> extend class XmlNode { [MatchOnThis] public NodeType : XmlNodeType {} [FieldInOption ("Attribute")] [FieldInOption ("Element")] // ... public Name : string {} [FieldInOption ("Attribute")] [FieldInOption ("CDATA")] // ... public Value : string {} // ... } match (some_xml) { | XmlNode.Attribute (name, value) => ... | _ => ... } </xmp> <p> Anyway, just an idea ;-) </p> <p> <i>-- Michal</i> </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Mar-06.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Mar-06.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Mar-06.html Sun, 06 Mar 2005 13:55:00 GMT 17 Feb 2005: Porting tests from C# to Nemerle <p> I have been playing a little bit with our <a href="http://nemerle.org/svn/nemerle/trunk/tools/cs2n/">C# to Nemerle</a> code converter. The tool created by Bartek is still under development. It sometimes produces code, which needs some more tweaking to compile silently with <tt>ncc</tt>, but it is already quite powerful. </p> <p> As a life test I tried converting positive test-cases from Mono's <a href="http://svn.myrealbox.com/source/trunk/mcs/tests/">C# compiler test-suite</a>. I took quite behavioral strategy: do not touch neither original C# code nor produced Nemerle programs, just test. I was wondering how much I can get with this and today I reached the number of <a href="http://nemerle.org/svn/nemerle/trunk/ncc/testsuite/frommcs/">200 working cases</a> from over 600 original ones. Note that they are probably not the best examples on HOW to program in Nemerle. ;-) </p> <p> Quite nice I would say, taking into account that there are some features, which we do not support (unsafe code, iterators utilizing <tt>yield</tt>, etc.), unstable state of the converter and the fact that test-cases are mostly malicious programs, which used to crash <tt>mcs</tt>. The most problematic currently are the tests with implicit conversions, which will be supported in Nemerle only with the new typing engine, which Michal is currently working on. </p> <p> The problem even with working cases was that our testing program does some more checks when executing regression tests. I had to provide output for many of them and mark / fix warnings issued by Nemerle compiler (mostly about unused variables). But at the end it was fun to see a few more hundreds of '<i>Testing blabla.n...verify...run...<font color="green">passed</font></i>' lines during our nightly builds. One nice thing about compilers is that they are text to text tools and are quite straightforward to test (given that you have good test-cases). </p> <p> The tool will be included in our next release. Of course it's better to write Nemerle code from the very beginning using all its unique features. But in case you are not familiar with the new language and have some medium sized application in C#, it can help you dive into functional programming more easily. </p> <h2>Cleaning meta-data information</h2> <p> One of the issues I have found annoying during this work was that we emitted much unnecessary meta-data information to the assembly (it posed some problems in custom attributes tests). So what and why was that? </p> <p> You must remember that Nemerle has features not always fitting into .NET model and that it supports parametric polymorphism (aka generics) on 1.1 .NET framework (like Java 1.5 on its generics-lacking runtime). So, they can live safely within compiler, by to be able to create and load Nemerle assemblies without loosing information about special types and generics we have to encode them somehow in assemblies. </p> <p> .NET custom attributes come very handy to do this. For example if we have </p> <xmp class="code-csharp"> variant Tree { | Leaf | Node { left : Tree; value : int; right : Tree } } foo (l : list [Tree], x : int -> int) : int * Tree {...} </xmp> <p> we encode them to something like: </p> <xmp class="code-csharp"> [VariantType] class Tree { [VariantOptionType] class Leaf : Tree { } ... } [MemberType ("list(Tree) * (int -> int) -> int * Tree") foo (x : list, x : Func1) : Tuple2 { ... } </xmp> <p> This way we can easily recreate what <tt>Tree</tt> is and what is the type of <tt>foo</tt> function after saving and loading of code to assembly. </p> <p> Now, what was the original problem with polluting meta-data? We were emitting those special attributes for every member of every class. So even if some field had type <tt>int</tt>, which is simply expressible by <tt>System.Int32</tt> we produced some extra info to be consistent. Optimizing those cases resulted in some performance boost and a very nice thing - Nemerle produced assemblies are now basically not distinguishable from csc or mcs generated ones, if you do not use any Nemerle specific types. </p> <p> After we implement the usage of runtime generics, this will be the very common case. For example functional type <tt>'a -> 'b</tt> will be translated to <tt>Func1 &lt;'a, 'b></tt>. This is what I understand by multilingual platform (ignoring many of its tweaks, about which we might tell later) ;-) </p> <p>-- <em>Kamil</em></p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Feb-17.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Feb-17.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Feb-17.html Thu, 17 Feb 2005 13:55:00 GMT 27 Jan 2005: Comments ;-) <p> I took some time and set up a simple comment system. You just need to go to a specific blog entry (in <tt>archive/</tt>), and there will be a list of comments along with a form to post. It was a nice exercise in Nemerle programming. </p> <p> From the other news, <a href="http://www.advogato.org/person/lupus/diary.html?start=13">lupus</a> did some mambo jumbo in mono to get our testcase 4x as fast as it used to be. Impressive! If only the other implementation was as fast... I guess I can now report this as a performance issue with a nice argument in hand. </p> <p> My girlfriend has a birthday today. I also will in 3 days. Well, yet another year and I'll be closer to 50 than to day of my birth (it sounds so sad and serious ;-) </p> <p> And this Garden State soundtrack is really great! </p> <p> -- Michal </p> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Jan-27.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Jan-27.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Jan-27.html Thu, 27 Jan 2005 13:55:00 GMT 26 Jan 2005: What I think about exceptions performance <p> One of the rules the .NET was designed with in mind was that exceptions are only for exceptional situations. Therefore performance doesn't matter. The same thing can be noticed with delegates. </p> <p> But the above assumption is a piece of crap. It is quite common to break the loop using exceptions in functional languages. Exceptions are treated there as a form of structuring program. Nobody would do it in .NET. </p> <p> However there are cases when using exceptions would simplify program structure a lot, and I still cannot do it, because exceptions are soooooo slow. </p> <p> I've been writing my MSc thesis right (<i>Let S be a partial preorder on type variables...</i>), I mentioned it some time ago <a href="http://nemerle.org/blog/archive/2004/Sep-07.html">here</a>. I was clearly wrong assuming I've got everything done ;) </p> <p> Anyway in addition to the theoretical background, I want to implement it. Until now I've created about 150k of code without even compiling it, which doesn't seem a good thing, but I cannot figure out a way to test pieces separately. Now what does it all have in common with exceptions? </p> <p> Well, in the new typing engine it will be possible to save entire state on the stack, type some expression, inspect it, discard and pop state from the stack. All side-effect free. It can be usable for macros. It also simplifies things in many places -- for example to see what 'x' is we need to check for 'x' (a local), 'this.x', 'System.x', 'System.Foobar.x' and so on. This is easily done using the above mechanism (save, try typing, see if there were an error, restore and if there were no error run typing again). </p> <p> But the most important point where it is used is overload resolution -- we need to try several possible resolution of the symbol being called. <p> Now, handling errors (user errors in programs) as exceptions in compilers is quite reasonable -- you can catch them for example in method compilation procedure and get just-one-error-in-a-method behavior, you can catch them somewhere else. And in general there is no performance issue here -- if any single <tt>throw</tt> will result in an error message, then there is no performance problem, exceptions aren't <b>that</b> slow. </p> <p> But now, when we have this stacked typing, it is common to have ,,user errors'' in normal execution paths. In overload resolution it is common to just one of several possibilities to be error-free. So we cannot use exceptions in overload resolution. And if we cannot use exceptions in overload resolution, this is as bad as we couldn't have used them at all. We're back in the good ol' C model of checking return values for errors. That's why I don't think that exceptions should be <b>that</b> slow. </p> <p> What does it mean ,,that'' slow? Well under mono/amd64 throwing and catching an exceptions takes about 18k cycles. It's quite similar on mono/x86. The other implementation I tasted wasn't better. All this means, that using my super hiper turbo fast machine I'm able to throw 100k exceptions per second. So using it for any other purposes then error reporting and cannot happen kind of situation is a performance suicide. </p> <p> And here is the piece of (C#, hehe) code that I used for the tests. </p> <xmp class="code-csharp"> using System; class M { int counter; Exception e; void throwing_foo (int x) { if (x % 3 == 0) throw e; } void testfoo (int x) { try { throwing_foo(x); } catch (Exception e) { counter++; } } public static void Main() { M m = new M(); m.e = new Exception(); for (int i = 0; i &lt; 1000000; i++) m.testfoo(i); Console.WriteLine(m.counter); } } </xmp> <div align='right'><a href='http://nemerle.org/blog/archive/2005/Jan-26.html#comments'>Comments</a></div> http://nemerle.org/blog/archive/2005/Jan-26.html Kamil Skalski (nazgul@omega.pl), Michal Moskal (malekith@pld-linux.org) http://nemerle.org/blog/archive/2005/Jan-26.html Wed, 26 Jan 2005 13:55:00 GMT 16 Dec 2004: Debugging support for Nemerle and other news <p> We were quite silent lately, but this is because we have many Nemerle parts under much rework. To name a few, we are currently developing a C# to Nemerle converter (already transforms and successully runs over 100 testcases from Mono's mcs testsuite), interactive interpreter, plugin for MS Visual Studio, debugging support for Nemerle compiled assemblies and fixing many bugs. Michal is working on the New Typing Engine, which will bring powerful type inference improvements to the compiler. </p> <p> I (Kamil) was focusing mostly on bugs and reworking of compiler's API. In a meantime I tried adding debugging support in code generation. It was much simpler than I first thought about - just a few calls of <tt>ISymbolWriter</tt> during <tt>System.Reflection.Emit</tt>ing the assembly. And here it goes: </p> <img src="http://nemerle.org/images/debugging2004_12_16.jpg" alt="debugging" /> <p> With the svn version of compiler you are able to generate debuggable assemblies, step through code and inspect memory using MS CLR Debugger. Of course this work is in early stage and there are many problems. Locations are not yet stored correctly through entire compilation trees, so from time to time the "yellow" selection will go to some crazy places, but it will be hopefully easy to fix everywhere. </p> <p> Debug support not yet works on Mono, but we are having the discussion with Mono developers and probably it will work here also soon. </p> <p> I was also developing MS Visual Studio plugin for Nemerle using <a href="http://msdn.microsoft.com/vstudio/extend/">VSIP</a>. It will be nice to connect all the debugging stuff with </p> <img src="http://nemerle.org/images/visual2004_12_16.jpg" alt="visual studio" /> <p> Visual Studio, but I was not able to find out how to do this (any help about developing in managed VSIP would be nice). The potential is great, code completion