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? "

30 of 344 comments (clear)

  1. GNOME and .NET change of heart by Marx_Mrvelous · · Score: 4, Funny

    After reading Miguel's long response to the Register article, I've really changed my mind about .NET architecture. I think I'm going to get a book and start learning it, maybe try to contribute to his effort.

    --

    Moderation: Put your hand inside the puppet head!
    1. 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:
    2. Re:GNOME and .NET change of heart by kin_korn_karn · · Score: 3, Interesting

      Java is a raging success at the enterprise level. You can hire H1Bs straight off the boat to bash Java code for half the price of any other programmer.

      To implement a Java project you need the following:

      1 architect
      1 business analyst type
      X code monkeys, depending on the size of the project and the timeline.

      India supplies the code monkeys at 1/3 to 1/2 the cost of an American, while the two people who have communication skills are paid what they're worth.

      I'm sorry it's not PC. I like people from India. Sadly, half of what an american programmer makes is more money than a lot of people from India have ever heard of.

      It's a manipulation and a scam on both sides - India farms out its best minds to artificially raise their GNP (and increase their status in the world), while US companies get cheap labor without having to establish an overseas presence. Brought to you by Dubya and the Indian government. Praise Jesus!

      If you think this isn't real, talk to any US citizen who is a developer working in a non-Java technology. Talk to any H1B doing Java over here.

      *spit*

    3. 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)
    4. Re:GNOME and .NET change of heart by elflord · · Score: 3, Informative
      I have to disagree. First of all, it being illegal to pay them less means nothing. I think there's a loophole with consulting companies. They can bill at the same rate as citizen, but pay the slave^H^H^H^H^Hconsultant whatever they want.

      A friend of mine worked at one of these consulting companies, and their salaries were actually pretty decent. Of course, an anecdote doesn't prove anything, but suff"ice it to say, I am sceptical. However, I think the H1B visas should require a minimum salary.

      This is going to show my redneck heritage, but I believe this - we can't afford to have a bunch of non-citizens in the USA stealing jobs from citizens by undercutting us in every way.

      Well that's too bad, because the alternative is to have a bunch of non-citizens out of the USA stealing jobs from citizens by "undercutting" you.

      What we have with the H1Bs is the recipe to economic collapse, rapid inflation, etc.

      There's little in the way of evidence to support this claim. I would argue that on the contrary, isolationist policies are a sure recipe to doom. The problem is that there is change due to the unsustainable situation where people in India have much lower salaries than their American counterparts. Because of this, it's in the interests of companies to prefer the Indians, and fire the Americans since they're cheaper. A lot of people are getting burned by the transition (this always happens when economies undergo any type of transition) The key is to put the brakes on the transition so that no-one gets burned more than necessary.

      Just look at the early 20th century immigration boom. That eventually led to the great depression, which led to WWII.

      Post hoc ergo propter hoc. Lots of things led to the great depression (ponzi schemes, a poorly regulated stock exchange, and an unsustainable boom), and lots of things led to WWII (namely, Germanys hardship had a lot to do with the "victors justice" at the end of WWI

  2. Mondrian for .NET by cdmoyer · · Score: 4, Informative

    Another good example, as covered in Dr. Dobbs last issue, is Mondrian. You can read a paper about it here(it's a PDF). You can download the compiler and view documentation at the mondria-script web-site.

    Here's a blurb from Dr. Dobbs:
    Mondrian is a modern, purely functional language specifically designed to leverage the possibilities of the .NET Framework.

    --
    /* CDM */
  3. What about speed? by tal197 · · Score: 5, Interesting

    Does anyone know how .NET does for speed?
    ie, Java takes an absolute age to initialise which makes it unsuitable for desktop applications or utilities (although people still try... maybe in a few years' time...).

    Does .NET introduce an even bigger overhead, or have they sorted it out?

    Also, is there any overhead for languages that aleady use a VM (eg, python, perl) if they switch to .NET instead? Will the tailor-made version be more efficient because it's designed with the language in mind, or does the benefit of having all the optimisations done on a common system compensate for that?

    I really like the idea of a common cross-platform runtime, but not if it makes my text editor take 5 seconds to load!

    1. Re:What about speed? by Rentar · · Score: 3, Interesting

      .NET has beend designed more for speed, than for platform independence (but it should, at least in theory, be platform independent nevertheless.) .NET is ment to be Compiled to native code, instead of beeing intepreted (like a JIT with Java does, although current HotSpot technology is a bit more complex than this), but it is not compiled every time it is run, but during install-time. So you should get almost no loss in startup-speed and execution speed.

      Disclaimer: my position on .NET is similar to Miguels. I don't like what MS is doing, but like the .NET framework from a technical point of view.

    2. Re:What about speed? by NulDevice · · Score: 4, Interesting

      I've been playing with .NET apps - simple ASP.NET ones, so far - on my PIII 500 laptop. I can field a little of your question...

      Okay, running IIS5, WIn2000, Visual STudio .NET and the app all at the same time - the first time an ASP.NET app runs it takes an absolute age - but it's compiling, much like a JSP-Servlet compile.

      After that it's surprisingly zippy, considering how I'm abusing this poor laptop at the same time with a gazillion other apps. It's much faster, at any rate, than old-fashioned ASP.

      There's some anecdotal evidence for you. I haven't hit it with VeloMeter or anything so I haven't seen how well it scales yet.

      I'm thinking the real big primary advantage of .NET is with strong typing and a fairly rigorous object model, it's going to force a lot of hack VB programmers to get their sh!t together and start writing code that doens't look like the top-down crap I wrote in Apple Basic in 4th grade. Wow, maintainable code, what a concept.

      --

      ----
      "I used to listen to Null Device before they sold out."

    3. Re:What about speed? by egomaniac · · Score: 3, Interesting

      A JIT does not interpret Java. Ever. Under any circumstances.

      JIT is short for Just In Time *Compiler*. A JIT compiles Java bytecode to native code prior to running it. It is in fact this compilation which lead to the slow startup time visible under Java 1.1 and 1.2 (without HotSpot), because the JIT could not interpret code. It had to compile *everything*, even if it was just initialization code which would only run once.

      HotSpot, the next generation of VM technology which is integral to Java 1.3 and 1.4, features an interpreter which is used initially. This gives HotSpot very fast startup time, because it initially does no compilation. As HotSpot decides that a particular method needs to be compiled, it does so in a background thread while continuing to run the interpreter. When the compilation is finished, it swaps in the native version (the current version can do this even if it is in the middle of running the interpreted version). This gives HotSpot two big speedups: firstly, because it uses the interpreter initially, startup is faster, and secondly because it compiles fewer methods (IOW, only ones which actually benefit from compilation) it can spend more time optimizing each method.

      HotSpot beats Visual C++ in most benchmarks. It is damned cool technology, and most people that claim Java is slow haven't played around with it in a long time. Java 1.4 is ripping fast.

      --
      ZFS: because love is never having to say fsck
  4. Re:Who thought this? by relinquish · · Score: 3, Informative
    As far as I understand the issue is a performance one.

    For example, scheme is hard to compile towards the JVM or standard C because both lack proper tail call implementation (poping the parameters in the stack before calling a function in tail position).

    You can of course circumvent this because as you say the target language is Turing complete, but you lose a lot on performance if the target isn't tailored to this particular use.

    --
    Relinquish
  5. boy, good thing by Frothy+Walrus · · Score: 3, Funny

    all four Prolog and LISP Win32 applications developers were getting nervous.

    nice solution to a non-issue.

  6. Re:Who thought this? by entrox · · Score: 3

    The problem lies in the CLS: Common Language Specification. .NET libraries and applications can be written in a colorful mix of languages and must be able to interoperate. Interfaces tend to look a little bit differently in functional languages than in imperative ones. If I use feature X of my preferred language in my library, which isn't available in your preferred language, you won't be able to use the library how it's supposed to be used. Herein lies the difficulty: making those inter-language operations as painless as possible. It's a hard problem and while going to a lowest common denominator is surely a possibility, it surely will alienate the users of say functional languages.

    --
    -- The plural of 'anecdote' is not 'data'.
  7. 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.

  8. IL, like Java Byte Code, is simply assembler by xacto · · Score: 3, Interesting

    Let me ask you all a question: If any language that you currently use is compiled into native machine code (for x86, or PPC, etc.), then why wouldn't .NET or the JVM support it?

    You have to remember that both IL and JBC (Java Byte Code) are essentially virtual CPUs that have some high-level features tacked on to simplify implementing certain kinds of langauges. However, they are still just basic assembly like langauges. Anything one could do in native assembler, one could do in IL or JBC. In fact, not trying to support one or the other, IL is probably a slightly better candidate here because Microsoft uses it to compile to native x86 assembler. Hence, there is support for direct memory manipulate (something the JBC doesn't have).

    So, can someone implement Lisp using IL? Why not? They did it with C or assembler before. Can someone implement Smalltalk? David Simmons already has at http://www.smallscript.com.

    I applaud Miguel for trying to bridge the gap between the Windows and *nix world in innovative ways. Good luck!

    1. Re:IL, like Java Byte Code, is simply assembler by JohnsonJohnson · · Score: 4, Interesting

      The problem is not whether a compiler/interpreter for any language can use teh VM as the targeted back end. The problem is whether Microsoft's claim of language interoperability is true. So far the answer seems to be no. One can use all of their favourite languages features on a .NET compiler/interpreter but they cannot export any interfaces that may rely on some of those features: dynamic typing, closures, unsigned types etc. So what happens is Microsoft ends up effectively promoting a single programming style: essentialy C# except the syntax can be modified to look like your favourite language. No self respecting LISP, Scheme, ML, Haskell, Prolog etc. programmer is going to deliberately write inefficient code (and imperative style explicit looping is usually terribly inefficient in these languages as one example) simply because they are living withing the .NET CLR jail cell. Therefore they will use the language with the least impedance mismatch to the CLR: C#.

      As has been mentioned often, the Java JVM has many of the same issues. However the developers of the Java JVM never claimed to efficiently support languages other than Java as first class citizens. The recent furor over the .NET CLR makes this seem like one tof the few wise choices they made so far.

      So to reiterate, the issue is not whether a language can be targeted to the virtual machine, it's whether the object code produced from source code in two different languages can interoperate and the answer is simply no, only the subset of features shared by C# and other languages can interoperate.

  9. Think strategy, not technology by pubjames · · Score: 3, Offtopic

    A lot of the debate about .NET and the open source focuses on the technology, and not the strategy.

    Let's consider some facts first. One of Microsoft's basic strategies is the complete domination of markets. They make no secret of this (although they have not been successful at it outside of the desktop space). Here are some instances where senior Microsoft people have stated they want to completely dominate a market:

    1) Internet access with MSN.
    2) The handheld market with Windows CE
    3) The game console market with X-Box.

    In all three cases above, they have made it clear that they intend to dominate that market, and have even stated that it is "the Microsoft way" to do so. They're not interested in 50%, they want 100. Admittedly they haven't yet been successful in this any of the above markets (in fact I think we can now safely say that they've failed with Internet access), but that is their intent.

    So, what has this to do with .NET? Well, .NET is a technology, but it is also a strategy. Its aim is to completely dominate software development in the future.

    Now, Microsoft's strategists will have spent a long time thinking about this. They will have hypothosized about potential problems, and developed contingency plans. Microsoft knows that in order for .NET to be successful, they need to win developers over to it. In order to do that, they need to give the appearence of it being an open and non-threatening platform to use. But that's only appearances. Their aim with .NET is to completely dominate the provision of any type of software service over the internet (which will include pretty much everything within a decade) and to get their slice of every transaction made.

    That's why I despair when I hear people in the Open Source community talk about implenting stuff in .NET. If you think you will ever beat Microsoft by playing by their rules then you have your head in the sand. Think about what contingency plans Microsoft might have in place. Remember that they have a war mentality - what would you do if you were Microsoft? Think about the Haloween memos.

    Has anyone, for instance, looked through all Microsoft's patents, to check that their isn't a surprise that they could pull out of the sack if things aren't going their way? Has the Gnome Foundation, for instance, got the financial means to defend itself should Microsoft attack it legally? Why are some parts of the .NET strategy still vague, when Microsoft is "betting the barn" on it?

    .NET is perhaps great technology. But I implore everyone in the OSS community to stay away from it. Bill Gates will tell you that the best technology doesn't necessarily win in the long term, it is what has mindshare. OSS is getting more mindshare every day. Don't help MS by supporting their technologies. Your software project will get killed if it starts to threaten MS if you do.

  10. .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!

  11. 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.

  12. 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.

  13. Haskell by hoggy · · Score: 5, Informative
    Given that one of the main brains behind Haskell now works for Microsoft Research and has always been a strong proponent of FP on commercial platforms - I'd be surprised as heck if the Glorious Haskell Compiler wasn't targetting .NET real soon.

    I took a look around and found this link to a guy called Don Syme at Microsoft Research who appears to be working on just this.

    There's also the Mondrian project, which implements Haskell.

  14. 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

  15. Initialization speed and bytecode verification by brad.hill · · Score: 3, Informative

    Part of Java's slowness in initializing is that it does extensive security oriented bytecode verification of every class loaded. If .NET doesn't do that, it will be faster, but arguably not as secure against people rearranging the CLR bytecodes in ways that a compiler conforming to the security spec wouldn't. BTW: You can disable this as a command line option to your JVM and speed things up if you trust your .class files, but the default is to be secure.

  16. 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.

  17. 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

  18. Re:Who thought this? by guinsu · · Score: 3, Interesting

    You know its intersted that Java wasn't designed for having lots of short-lived objects. Think of the performance benefits programmers might see (like in for loops, using String instead of StringBuffer etc).

  19. COM by Weezul · · Score: 3, Interesting

    Purely functional langauges stateless work quite well under an object oriented frame work. Yes, I know objectes are supposed to have state. Object level states are handled very well in all modern purely functional langauges via monads. I think Haskell has transioned to COM programming very nicely.

    As a side note, anyone notice how all the current langague research is going on under Windows with Microsoft grants? Currently, most of the projects simultaniously support Windows and Linux, but these projects are currently focusing a lot of attention of COM and .NET. They are not even adding support for the various open source technologies like CORBA. I expect that you will find open source operating systems to be a bit behind the times langauge wize in a few years.

    --
    The Christian religion has been and still is the principal enemy of moral progress in the world. -- Bertrand Russell
  20. 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"
  21. Why Functional Programming Matters by dstone · · Score: 5, Interesting

    Okay, I apoligize for an extra long post here, but I still see people mischaracterizing functional programming. So I'm going to take a few excerpts from "Why Functional Programming Matters" by John Hughes. It's a short paper, worth your time if you're new to the functional paradigm.

    No Side Effects:
    Functional programs contain no side-effects at all. A function call can have no effect other than to compute its result. This eliminates a major source of bugs, and also makes the order of execution irrelevant - since no side-effect can change the value of an expression, it can be evaluated at any time. This relieves the programmer of the burden of prescribing the flow of control. Since expressions can be evaluated at any time, one can freely replace variables by their values and vice versa - that is, programs are "referentially transparent". This freedom helps make functional programs more tractable mathematically than their conventional counterparts.

    Higher Order Functions:
    Functional languages allow functions which are indivisible in conventional programming languages to be expressed as a combi-nation of parts - a general higher order function and some particular specialising functions. Once defined, such higher order functions allow many operations to be programmed very easily. Whenever a new datatype is defined higher order functions should be written for processing it. This makes manipulating the datatype easy, and also localises knowledge about the details of its represen-tation. The best analogy with conventional programming is with extensible languages - it is as though the programming language can be extended with new control structures whenever desired.

    Lazy Evaluation:
    A complete functional program is just a function from its input to its output. If f and g are such programs, then (g . f ) is a program which, when applied to its input, computes g (f input). The program f computes its output which is used as the input to program g. This might be implemented conventionally by storing the output from f in a temporary file. The problem with this is that the temporary file might occupy so much memory that it is impractical to glue the programs together in this way. Functional languages provide a solution to this problem. The two programs f and g are run together in strict synchronisation. F is only started once g tries to read some input, and only runs for long enough to deliver the output g is trying to read. Then f is suspended and g is run until it tries to read another input. As an added bonus, if g terminates without reading all of f 's output then f is aborted. F can even be a non-terminating program, producing an infinite amount of output, since it will be terminated forcibly as soon as g is finished. This allows termination conditions to be separated from loop bodies - a powerful modularisation. Since this method of evaluation runs f as little as possible, it is called "lazy evaluation". It makes it practical to modularise a program as a generator which constructs a large number of possible answers, and a selector which chooses the appropriate one. While some other systems allow programs to be run together in this manner, only functional languages use lazy evaluation uniformly for every function call, allowing any part of a program to be modularised in this way. Lazy evaluation is perhaps the most powerful tool for modularisation in the functional programmer's repertoire.

    Why you might care:
    Modularity is the key to successful programming. Languages which aim to improve productivity must support modular programming well. But new scope rules and mechanisms for separate compilation are not enough - modularity means more than modules. Our ability to decompose a problem into parts depends directly on our ability to glue solutions together. To assist modular programming, a language must provide good glue. Functional programming languages provide two new kinds of glue - higher-order functions and lazy evaluation. Using these glues one can modularise programs in new and exciting ways... Smaller and more general modules can be re-used more widely, easing subsequent programming. This explains why functional programs are so much smaller and easier to write than conventional ones. It also provides a target for functional programmers to aim at. If any part of a program is messy or complicated, the programmer should attempt to modularise it and to generalise the parts. He should expect to use higher-order functions and lazy evaluation as his tools for doing this.

  22. Re:Biggest oxymoron? by markj02 · · Score: 3, Interesting
    OCAML is comparable to other safe, compiled languages, including Java. SISAL and similar functional programming languages for numerical applications can even beat Fortran, mostly because there are more opportunities for optimization.

    Functional programming language are an excellent match to the needs of modern processors. In fact, the only reason C and Fortran aren't complete dogs is because we invest enormous amounts of effort in adding special-purpose processor features to support imperative constructs, including speculative execution, branch prediction, byte-wise updates, instruction-level parallelism, etc. None of that hardware does any good for the computation itself--it just eats up precious real-estate in order to support the semantics of languages like C and Fortran. Functional programming languages not only remove the need for most of that hardware, they are also nicer to program in.