Slashdot Mirror


Functional Languages Under .NET/CLR

Numen writes "With all the talk of .NET being thrown about there is a common factor occuring through many discussions, namely the claim that .NET will be unable to address functional and logic languages such as Prolog and LISP. To this end I would like to drawn peoples' attention to two resources, that shown how this may well be a non-issue, and to ask, does this change anybodies mind? "

16 of 344 comments (clear)

  1. Who thought this? by saforrest · · Score: 2, Insightful

    What basis for thinking this would anybody have?

    As long as the language is Turing-complete, it should be possible; the question is in the level of difficulty, and I don't see why .NET would be harder to support than, say, TCP/IP or HTTP. I mean, Emacs was written in LISP; if they can do that, is .NET such a challenge?

    Perhaps I've misunderstood the claim; in that case, perhaps it would've been useful for the poster to include a link detailing the rationale behind the claim that functional languages wouldn't work.

    1. Re:Who thought this? by JamesOfTheDesert · · Score: 2, Insightful
      As long as the language is Turing-complete, it should be possible;

      The question has to do with getting the language to run well, and correctly, on a stack-based VM.

      --

      Java is the blue pill
      Choose the red pill
    2. Re:Who thought this? by smallpaul · · Score: 3, Insightful

      As long as the language is Turing-complete, it should be possible; the question is in the level of difficulty, and I don't see why .NET would be harder to support than, say, TCP/IP or HTTP. I mean, Emacs was written in LISP; if they can do that, is .NET such a challenge?

      There is a big difference between implement EMACS or TCP/IP *in* a language and implementing a language *on* .NET! Your mixing apples and oranges.

      Nevertheless, there is no question whether functional and logic languages can work on .NET. The only question is whether they can work with sufficient efficiency that they will be tools, not toys.

    3. Re:Who thought this? by jwpalmer · · Score: 4, Insightful

      I think that this is an instance of an unclear question. The question is not "Is it possible to implement functional languages in .Net?", but rather, "Do the bytecode primitives efficiently support execution of functional language primitives?"

      You might be able to implement a functional language interpreter supporting closures, lazy evaluation, etc., in the standard bytecode, but that's not the point. The point of the CLI is to effectively support efficient execution of programs written in ANY language. Therefore, writing another layer on top of the bytecode to support features unique to functional languages eliminates many advantages functional languages provide, and can potentially disallow correct execution of complex functional programs.

      So, if the bytecode representation was designed to support object-oriented languages, it's probable that it WILL NOT efficiently support recursion and partial evaluation. This is the crux of the argument, and why people are concerned with the existing bytecode spec.

      There is a lot of work being done in this area, though, so there is hope that this will be resolved. After all, Microsoft does have some of the best minds in functional programming thinking about the problem.

      For more information, see:

      http://research.microsoft.com/~dsyme
      http://www.research.microsoft.com/~emeijer
      http://www.mondrian-script.org

      - j

  2. Re:GNOME and .NET change of heart by Masem · · Score: 5, Insightful
    I think the idea of .NET is good too, but realistically, we already saw it for Java.

    I wonder where we would be if Microsoft had enbraced (but not extended) Java, such that both Sun and MS had meanful discussions on how to expand it and yet keep the promise of "Write Once, Run Everywhere" (ie, no MS-specific extensions, and so forth). The idea that any vendor could release code that would run on 100% of the computers out there, not just 95%, would be a godsend.

    While .NET, and efforts by Miguel and Ximian to create Mono, and probably similar efforts inhouse at Apple, appear to offer the same promise, I still expect that we'll see a lot of Windows-specific hooks that would prevent a good chunk of code of being cross compatible. Not that one can't write fully compatiable .NET code that runs everywhere, but I would not be surprised if MS offered programming goodies (cool widgets, eyecandy features, etc) that would be easily be limited to Winboxen and leave other implimentations of the virtual machine out in the cold.

    --
    "Pinky, you've left the lens cap of your mind on again." - P&TB
    "I can see my house from here!" - ST:
  3. Standard ML and Haskell implementations by hsenag · · Score: 3, Insightful
    Work has been done on implementing two major functional languages for .NET: Standard ML and a partial implementation of Haskell at the Mondrian site (it already seems to be slashdotted so I won't make this worse).

    The SML.NET compiler hasn't yet been released by Microsoft Research but hopefully it will be soon. As I understand it, it is a complete implementation of Standard ML, with a few (small) extensions to hook into the .NET object model.

    In my opinion, this could be one of the best opportunities functional programming has to gain mainstream acceptance, because of the ease with which it will be possible to link functional code with imperative code.

  4. .NET is a quagmire by darkatom · · Score: 4, Insightful

    .NET is just another one of Microsoft's over-engineered solutions. It looks simple on the outside, but when you get down to it the complexity is overwhelming. It's really sad to see so many open source developers being lulled by Microsoft's latest technological tactic.

    Who out there remembers DDE, OLE, MAPI or DocObjects? How about MFC (.NET 0.5...)? If you do, remember how well (not very!) these "technologies" worked outside of the boxes Microsoft created them for? Has anyone out there actually tried to work with, for example, Exchange server?

    Microsoft fears clonability, and to prevent it they create complex APIs with lots of hidden underspecifications. Then they get developers on board by creating pretty, easy-to-use tools and hosting big developer conferences. And they make it feel cool through shrewd marketing. But at the end of the day, you find that you've spent 90% of your time trying to work around some deficiency. And it's not because Microsoft was especially dumb when implementing this stuff, its just that the stuff is needlessly complex to begin with!

    We're doing fine as we are. Don't drink from the .NET well!

  5. it really doesn't matter by markj02 · · Score: 5, Insightful
    You can compile both strict and lazy functional languages to CLR and JVM (there really isn't much of a difference between the two; even TRO can be dealt with reasonably well in the JVM). But don't expect miracles: the resulting code and performance will be usable but fairly mediocre.

    Why? One major advantage of functional programming languages for optimization is that the compiler knows that almost nothing can change behind its back: variables can't get updated, data structures can't get changed, etc. With VLIW architectures like Itanium and hyperthreading, functional programming languages can potentially do much better relative to traditional languages than on older processors. But in order to so so, their compilers need a degree of control over code generation that simply isn't available if you go through CLR or JVM.

    Furthermore, the entire runtime of a functional language is optimized for the kinds of allocation patterns that come along with functional programming, while CLR and JVM are optimized for OOP. For lazy functional languages, there are some additional issues when it comes to expressing lazy evaluation efficiently.

    Altogether, though, I think it really doesn't matter. CLR and JVM are good and fairly flexible platforms, but platform evolution won't stop here. If anything, Sun is a bit more honest in this regard, making no bones about the fact that JVM is primarily a Java platform, even though there are dozens of other language frontends available for it; CLR claims universality, but really isn't any better than JVM.

    If you don't care that much about performance, you can use your functional language under CLR and JVM. If you want a high-performance functional programming language, you can use one of the dedicated native code compilers and runtimes that will continue to be available. CLR and JVM will not end the evolution of other runtimes.

  6. Efficiency and convenience by YoJ · · Score: 3, Insightful
    I don't think people are worried that there will never be a way to write functional programs in .NET. This is clearly possible. As someone else said, the IL virtual machine is like assembly with some extra features. The things people worry about are efficiency and convenience.

    To take one example, in Lisp you can pass nameless functions quite easily. So you might have a library that has a function to create a new button. One of the arguments to the function is a function that the library will execute when the button is pressed. In Lisp this is a trivial thing, you just create a function and pass it as the argument. But if nameless functions are not supported by the virtual machine, then this operation becomes very problematic.

    What if the nameless function is created dynamically by the program? How can the virtual machine compile this nameless function to native code before running the program? Unless the virtual machine knows how to compile Lisp code, it cannot. It may be that the Lisp library must be changed to accept some other form of argument for the callback for efficiency reasons. If most of the work you do is just calling libraries and putting things together, you just lost one of the biggest features of Lisp. You have to trade off efficiency and convenience. If you use a native Lisp virtual machine, you have both efficiency and convenience.

  7. SML.NET by Tom7 · · Score: 4, Insightful

    I'm actually excited about the .NET framework (well, the CLR) because it will mean I can use my favorite functional language, SML, to write Windows apps.

    It's also from MSR: http://research.microsoft.com/Projects/SML.NET/

    Why do we care? In a really old thread I rant about the virtues of modern functional languages (and indirectly, SML). I think it's still relevant, though most of the other languages associated with .NET (ie, C#) have some of the same basic benefits now (like safety and portability). Here: http://slashdot.org/comments.pl?sid=6343&threshold =1&commentsort=0&mode=thread&cid=929697

    If you want to learn SML, or learn why I think it is so cool, maybe you'd like my under-construction tutorial called SML for Hackers: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tom 7misc/docs/sml/ml-for-hackers.txt?rev=1.3&content- type=text/vnd.viewcvs-markup

  8. Issues with Lisp and .NET... by Anonymous Coward · · Score: 1, Insightful
    Some of the issues are business related, and others are technical. The Lisp vendors don't see what the CLR buys them except a new-found slowness and a lack of portability. This may change with Mono, but there are some severe architectural issues to address.

    The CLR is based on the concepts of classes and single-dispatch, calling methods that "belong" to a class. Lisp's CLOS is built on multiple dispatch, and can cleanly support prototype object systems. It's hard to retrofit these capabilities onto a class and single-dispatch system, but it's easy to go the other way. Emulating multiple dispatch without the ability to re-compile on the fly leads to slow code.

    And, socially, many Lispers see Java, .NET, etc. as shallow attempts to mimic what they've had for over a decade: A portable, reflective, dynamic environment. Java and many of the .NET languages leave out key portions of Lisp. Lisp allows programmers to control how the code is read, translated, and then compiled without leaving the language. You can build infix Lisp in Lisp, with all the tools of Lisp at your disposal. Or you can eschew many of the tools in Lisp, all from Lisp.

  9. It's not going to be portable, folks by nagora · · Score: 3, Insightful
    MS are not going to make .NET portable. How obvious does it have to be before idiots stop posting comments about how the future could be great if .NET is done well?

    Look at it this way: if .NET is all MS says it will be then they will be opening themselves up to more and more competition; they will be creating a freer market for code than exists today. Surely no one here is so stupid as to imagine that's what MS wants?

    .NET will launch with as much support as the marketing department can get for it and then it will slowly morph.

    Each year will see a new version with more API calls etc defined and, you know what? Just after that all the MS programs that have been written using the beta versions of those API's will come out, well in advance of even the poor dupes that fork out for MSDN.

    Everyone apart from MS will be playing catch-up again.

    How many fucking times do you have to be done over before you learn???

    TWW

    --
    "Encyclopedia" is to "Wikipedia" what "Library" is to "Some people at a bus stop"
  10. Re:GNOME and .NET change of heart by rabtech · · Score: 5, Insightful

    What do you mean about "windows-only" hooks???

    I am constantly amazed at the complete LACK of understanding about what .NET is. Let me set the record straight: the functionality... the "API"... of .NET is contained in the core class libraries. Those are PUBLICLY AVAILABLE INTERFACES. There is nowhere to "HIDE" windows-only hooks. If you can have your MONO class library take CallX with four arguments of int just like the MS Windows version of the class, then you have CROSS PLATFORM capability. If Microsoft changes the class interface, then you change your corresponding class interface.

    Honestly! It's all Object Oriented; there is NOWHERE to hide anything from anyone! Implementation is another issue, but by virtue of the platform itself all the interfaces have to be public and accessible, which means they can be easily emulated. That's what mono is trying to do with WindowsForms; its the GUI component that Microsoft said was going to be Windows-only, except they are already working on emulating the public interfaces (though the implementation would be calling gtk/x)

    Please... THINK about this stuff before you post it. Its no like Sun can go and hide some new solaris-only hooks in the JVM that suddenly make it incompatible with other platforms! In order to have developers use the new hooks, they have to make them public, and then anyone could create a compatible class for their platform of choice.

    --
    Natural != (nontoxic || beneficial)
  11. True, but largely irrelevant over time by Ars-Fartsica · · Score: 2, Insightful

    I agree that users of non-OO/imperative languages will be forced to accept a lower common denominator if they employ .Net framework classes, but I predict that the benefits will outweigh the loses. Most exotic language features go unused for good and bad reasons, and as processor speed increases and memory cheapens, framework portability and coder productivity will outstrip the benefits of relying on the exotic features.

  12. Re:GNOME and .NET change of heart by ClosedSource · · Score: 2, Insightful

    "I wonder where we would be if Microsoft had enbraced (but not extended) Java, such that both Sun and MS had meanful discussions on how to expand it and yet keep the promise of "Write Once, Run Everywhere" (ie, no MS-specific extensions, and so forth)."

    I wonder where we would be if Microsoft had just ignored Java. Despite all the complaints about extending Java, I think MS's adoption of it made it much more widely accepted than it otherwise would have been. In that case Java would not be evidence in the antitrust suit, and the possibility of the court ordering MS to ship with Java would be even more remote than it is today.

  13. Re:What about speed? by Anonymous Coward · · Score: 1, Insightful

    I tried the same test:

    is x prime ? x < 1000000

    java 43,421 sec
    c# 24,769 sec

    (java 1.3.1, .net 1.0)
    (win2000, XP1800+)

    class Prim
    {
    // c# static void Main (string [] args)
    // java static void main (String [] args)
    {
    for (long a = 2; a < 1000000; a++)
    {
    // c# bool prim = true;
    // java boolean prim = true;
    // c# for (long b = (int)System.Math.Sqrt(a); b > 1; b--)
    // java for (long b = (int)Math.sqrt(a); b > 1; b--)
    if ((a % b) == 0) { prim = false; break; }
    // c# if (prim) System.Console.WriteLine(a);
    // java if (prim) System.out.println(a);
    }
    }
    }