Thursday, April 9, 2009

Clean Programming Language: the insanely great, the weird and the short-sighted

If you are reading this blog, chances are you are one of those people who think that Haskell is the most beautiful language ever. Well, you are wrong! Haskell is only the second most beautiful language ever, after Clean (they actually want you to register before downloading, so don't click that link).

The insanely great:
  • Like Haskell, but simpler. Haskell is primarily a research language. Monads, monad transformers, lifts, arrows, templates, bang patterns, etc. etc. get added to GHC on a regular basis. If you want to use Haskell, you'll have to constantly deal with unproven technology in FPL design, like monads and monad transformers. Clean is simpler. If you know Haskell (even if you don't fully grok monad trasformers), you can learn all there is to Clean in a few hours. For better or for worse, the features are pretty stable and simple, which brings us to my second point:
  • No monads necessary. That's right, a lazy functional language that can perform mutation and IO safely without monads. Imagine that! Clean uses uniqueness types in its otherwise Haskell-like type system. This choice turns out to be both easier on the brains and on the optimizer...
  • As fast as C (the compiler is very fast too), and it ain't no bullshit either! You may have heard from Haskell advocates that Haskell is as fast as C. Well, it's really a half-truth. Sometimes, there is simply no substitute for a good old-fashioned array and mutation of it. It's the only data structure known to man that gives you O(1) read, write with a small constant factor to boot. Haskell can give you that, but your choices are: (1) state and other monads (that don't compose too well) with mutable arrays in GHC (that can cause insane GC slow-downs), defeating the purpose of using them or (2) malloc'ed array hacking. If you look at the Shootout entries, Haskell entries are ugly unsafePerformIO and malloc-using hacks with everything stuck into IO monad, where Clean is idiomatic and simple, and still faster!
The weird:
  • 1980s called, they want... If your Clean program encounters a runtime error, like off-by-1 access, it will print a message naming the error and quit. This may have been good enough in the 80s, but these days I expect more finesse. Haskell allows you to handle these situations in a customized way.
  • No FFI. WTF?
  • Have someone who speaks English natively proof-read your books, manuals, etc. I won't go into detail here. I too suck at writing.
The short-sighted:
  • License. For a long time, Clean was closed-source, offering only commercial licenses. A few years ago, Clean was released as open source under LGPL. Can you now write and distribute your closed-source commercial code using Clean? I'm not a lawyer, so I couldn't give you a definitive answer, but in doing so, you would be incorporating part of Clean in your generated binary (statically linked runtime). This might not sit well with LGPL and the Free Software Foundation that may demand that you make your code open-source for doing that.
  • Development model. Clean may be open-source, but it's basically developed in-house. I do believe that programmers should be paid for their time and expertise developing software, especially programmers and brilliant as the authors of Clean must be, but the reality is that programming languages are different from most other software: As a consumer of a programming language, your investment both learning and writing code in it is tremendous. You want to be assured that your language will continue to exist in the future and won't cost an arm and a leg later. You simply won't use a language for anything important, unless you get these assurances. That's why, unless your vendor is a predictable monster like MS, for a programming language to be viable it has to either have open standards and multiple vendors, or have a fully open and distributed development and place no restrictions on the runtime (generated binaries) whatsoever. I want to ask Clean authors: is it better to have 5 users of whom 0 or 1 are paying customers or to have thousands of non-paying users, who however might make you famous and buy your books?

If you are developing performance-demanding code and love FP, Clean may be a very good choice for you, assuming that you don't shy away from LGPL and can live with some eccentricities like missing FFI and 80's style error messages.


  1. The LGPL is specifically designed to allow code licensed under it to be linked together with code not licensed under it. Originally it was called the "library GPL" for exactly this reason.

  2. @ habitue01

    Iffy for STATICALLY linking LGPL-licensed code into closed-source software.

  3. fpmatters, :

    Essentially, it must be possible for the software to be linked with a newer version of the LGPL-covered program. The most commonly used method for doing so is to use "a suitable shared library mechanism for linking". Alternatively, a statically linked library is allowed if either source code or linkable object files are provided.

    It wasn't hard to find. Please don't fud. thx

  4. Monads are certainly as well-tested as Clean's uniqueness typing -- there is nothing unproven about them.

  5. "Alternatively, a statically linked library is allowed if either source code or linkable object files are provided."

    That's what the OP meant by "iffy", though perhaps he should have provided the link. LGPL can have serious issues for instance in the case of embedded systems where tools like linkers are proprietary and cost big bucks.

    His point stands that almost all well-considered languages deal with this issue by providing a more permissive, MIT/BSD style license, at least for the linked runtimes. Even GCC uses a modified license rather than straight GPL/LGPL to cover this case.

  6. "LGPL can have serious issues for instance in the case of embedded systems where tools like linkers are proprietary and cost big bucks."

    Huh? The LGPL doesn't say anything about the cost of the tools, only that the linkable object files must be provided. You don't have to provide a toolchain, that's an exercise that's left to the reader.

    And it's not an untenable situation either. The ATI and NVidia Linux kernel drivers are shipped as object files, for instance. They don't do it because of the LGPL, but the point is that it's completely doable.

    All that said, yes, it would be nicer/more thoughtful to provide the runtime under a less restrictive license, like *every other compiler in the world*.

  7. If you don't like a LGPL license, you can buy a commercial one for Clean.

  8. It actually does have some sort of FFI, but it doesn't seem to be documented. There's a limited binding with OpenGL, for example, but I haven't looked into it much to see how it works. Seems like a really nice language, I gave up on Haskell in frustration, it has some great features but programming in my spare time shouldn't be that hard. Clean looks like it would be a good alternative, but it doesn't have the same community that Haskell does, sadly.

  9. Are you desperately in need of a hacker in any area of your life???

    then you can contact:

    I will help you at affordable prices, i offer services like
    -hack into your cheating partner's phone(whatsapp,,icloud,facebook and others)
    -Sales of Blank ATM cards.

    -hack into email accounts and trace email location -all social media accounts,

    -school database to clear or change grades,

    -Retrieval of lost file/documents

    -DUIs -company records and systems,

    -Bank accounts,Paypal accounts -Credit cards hacker

    -Credit score hack -Monitor any phone and email address

    -Websites hacking, pentesting.

    -IP addresses and people tracking.

    -Hacking courses and classes.

    my services are the best on the market and 100% security and discreet work is guaranteed.,...

  10. Tired of getting scammed by fraudulant hackers? HC can help you with any needs from security, to spying on a cheater, to changing grades, helping with credit issues, hacking any social media, and more contact today for prices and assistance. These people helped me out when I really needed it so I guarantee their work. Email at