Hacker News new | past | comments | ask | show | jobs | submit login
Why OCaml, Why Now? (spyder.wordpress.com)
106 points by croyd on March 17, 2014 | hide | past | favorite | 103 comments



Look, I love OCaml and it's my favorite language syntax-wise, but the real big elephant in the room is not its JS-backend maturity. Rather it doesn't have kernel thread support...all threads are user-level just like Python due to a global lock for garbage collection. This means threads do not run concurrently across multiple cores. This is UNACCEPTABLE in 2014 - roughly 8 years since processors went multi-core. Intel is talking about having hundreds of cores on a single die by next decade and having programs that can't take advantage of that is extremely limiting.

Xavier Leroy (the creator of OCaml) and his team at INRIA didn't think this was a big deal because when they were writing this stuff, processors were single core and had been since the beginning. Sure there were multiprocessor machines (not the same as multicore as there are multiple die), but those were only meant for servers/workstations. OCaml seemed very promising around 2006, the peak and end of the single core era with the Intel Pentium 4. What made OCaml so impressive was not only was it this beautifully simple, high-level functional language, but that the native compiler produced very fast code that was comparable to C/C++ performance. However, as multicore processors were introduced (Intel Core, Core 2), not having this capability made writing new code in OCaml less appealing. There are solutions like MPI, but that's lame. The same excuses you hear in the Python world about having true multithreading you hear in the OCaml world. Microsoft was able to do it with F#, which is essentially a clone of Caml by targeting their .NET CLR. Haskell is able to do it with GHC.

I still think OCaml is a wonderful language -- not having true multithreading doesn't make it useless. However, to me it has become more like a statically-typed Python which I can use for scripting. Having to use hacks like MPI to do multicore processing is a huge turn off in a multicore world. This is again nothing against the language, but the standard implementation needs a concurrent garbage collector and kernel threads. Otherwise I think OCaml may be doomed to irrelevance in the long run, which would be truly sad.


Apparently multicore ocaml is worked on again: https://github.com/ocamllabs/compiler-hacking/wiki/Multicore... https://github.com/ocamllabs/compiler-hacking/wiki/Multicore...

That being said you can still use multiple cores by using multiple processes, and that doesn't necesarelly imply MPI. OCamlNet (and probably some other libraries) provide a way to communicate between multiple OCaml processes.


Good to see work is being done on it, but until it's in the main implementation for at least a year...I wouldn't trust it on anything that matters.

The advantage of kernel threads is that they have way less overhead than a process (both in context size as well as more efficient memory caching at processor and OS level)...though more than a user-level thread. If there isn't any sort of message passing between two processes, the only mechanism I can think of of sharing data is shared memory (i.e and mmap) which is just as efficient as threads sharing the same process heap...but awkward (yes there are sockets, file IO, signals, queues, etc, but not as efficient). Even if OCaml provides a way to abstract that to be more palatable + safe -- my argument is that in a multicore world, kernel threads must be a first class citizen and the programmer shouldn't have to resort to tricks to harness it -- otherwise it's a major flaw that is going to prevent future adaptation. Also, as the number of cores increase, this is going to matter more and more...so hopefully this stuff gets out in the wild soon.


The multithreading situation in Haskell is pretty exciting. Simon Marlow's Parallel and Concurrent Programming in Haskell is the best new programming book I've picked up in a long time. And there are new developments since he wrote it (http://www.haskellcast.com/episode/004-simon-marlow-on-paral...). It would be a shame to give all that up.


What's interesting about Haskell in this regard is due to the pure functional nature, the Church-Rosser theorem applies...every function call could be executed in its own thread without protecting any resources with locks/mutexes/etc! I haven't studied the compiler design of Haskell, do you know if the compiler can delegate function calls to a thread pool automatically?


This won't be a problem for very long. See http://www.cl.cam.ac.uk/~sd601/multicore.md for the working design.


But "someday we'll only be a decade behind haskell" isn't much of a reason to choose ocaml over haskell.


I don't think multicore will be touted as a reason to choose OCaml over Haskell, but it will remove one of the reasons to avoid OCaml. Subtle but important difference :)


It won't though. Because it'll still be a decade behind haskell. People want more than just "ok, you can use multiple OS threads now". They want a concurrent IO manager, painless and seemless multiplexing of low cost green threads over OS threads, and high level concurrency and parallelism constructs. It is going to take a long time for ocaml to catch up to haskell in this department, and who knows what haskell is going to be offering by then.


Yeah, I should've addressed this in my post. Right now multicore doesn't mean squat to me as I'm using it for JavaScript support. I did investigate this, but forgot to add the links (others have already replied with) about work that is progressing nicely.

I'll update the post once this traffic calms down a bit :)


The situation is improving, specially with companies like Facebook and Microsoft using it.

However I do think that from the ML family, F# might be the one getting more widespread.


I'm glad that the author is picking up a new functional programming language, but choosing OCaml over Haskell because of support for the Javascript implementations strikes me as choosing a BMW over a Mercedes[0] because of the number of cupholders it has.

If you don't have a particular goal in mind (ie, "I work at Jane Street and need to be compatible with our existing code"), there are a number of other factors in the OCaml vs. Haskell discussion that are far more important.

> JS is the only realistic way to write web apps

Javascript is the only realistic way to write the front-end of webapps. But that doesn't mean you're wedded to it for your backend technology. And I don't think either OCaml or Haskell have sufficiently advanced DOM bindings, etc. that I'd recommend using either one for client-side work in the browser.

[0] I'm not sure if this is a flamewar topic for car nerds - my point is to pick two high-end luxury cars that are both well-respected and each have their own merits.


It sounds like you have a very language-centric view of the world. In practice, deployment is everything. (Why do people write code in Objective C? Because iPhone.)

Having a solid implementation for your target platform is very good reason to pick a language.


> It sounds like you have a very language-centric view of the world.

> Having a solid implementation for your target platform is very good reason to pick a language.

I'm not sure where you got that out of my comment; it was exactly the opposite.

My point was that neither OCaml nor Haskell have particularly strong implementations in this area (to my knowledge). Last time I checked, the ability to write Javascript using both languages was of experimental and/or novelty use only (hence the "cupholders").

And that still doesn't change the fact that a web app can be written in any language - the only part that needs to run in Javascript is the client-side. Depending on how you architect your app, this may not be much at all. (There are very few webapps that actually need much logic in Javascript - if you want to avoid JS[0] while writing complex webapps, it's actually very easy to do so in many cases.)

[0] or anything else that is translated into JS


> Last time I checked, the ability to write Javascript using both languages was of experimental and/or novelty use only (hence the "cupholders").

Facebook uses an OCaml js_of_ocaml-based frontend for a large chunk of their production code editing. Not a great video, but here's the CUFP 2013 talk on the topic: http://www.youtube.com/watch?v=gKWNjFagR9k


Haste is a strong, useful, and impressively complete Haskell to JS compiler.

Fay is used in production apps as well.

PureScript is less mature still but pretty nice.


I looked at Haskell options - fay and haste are both good, but not complete (try compiling tagsoup). GHCJS works, but generates 5mb JavaScript files.

This is what I meant when I said "by virtue of support for existing libraries". js_of_ocaml translates compiled bytecode and can therefore make any pure OCaml library work in JavaScript without recompilation.


Okay, sounds like a misunderstanding about what "web app" means. Sorry about that!

I think of a web app as the client side alone, which can be quite a substantial amount of code with something like GMail or Google Maps. Of course on the server side, you can make a mostly-independent choice of language, RPC mechanisms aside. But for the client side, I'd choose a language based on how well it compiles to JavaScript and can use browser API's and JavaScript libraries.

I don't know whether OCaml is ahead of Haskell in this space. I've tinkered with Elm a little bit.


>My point was that neither OCaml nor Haskell have particularly strong implementations in this area (to my knowledge)

They both do.


Car metaphors don't always match well with the situations they try to illustrate. Obviously if you had the chance to be offered either one of these two cars, you'd probably try them out and pick the one you feel the most comfortable with, but also which would best fit your needs. If all other factors have been weighted, and it boils down to the number of cup holders, would you stop there short of making a choice, because of the apparent superficiality of the argument? The author expressed his interest in both languages, and brought other arguments than just the js one.


BMW has legendarily terrible cup holders, by the way.


js_of_ocaml has excellent DOM bindings: http://ocsigen.org/js_of_ocaml/api/index

I'm also looking at whether TyXML can be used with js_of_ocaml for statically typed goodness: http://ocsigen.org/tyxml/


See, from what I took from the article, is that maybe it would make for a really solid client side web application language. On the other end of this, i feel like server side languages are moving more into the direction of multi-core support, i.e. Rust, Golang, Erlang... oCamel could fit nicely as a client-side web application language for DOM manipulation, like ClojureScript -- at least that's my take on it, but it really couldn't compete with the newer multi-core languages -- speedwise.


It does seem a little spurious at first, but part of the argument is that as js apps get larger, a static, functional language can be argued for to avoid problems with larger js codebases.


What's weirder about this is Haskellers have no problems using Fay, PureScript, and Haste for JavaScript.


I write all my javascript in haskell, and haven't had any problems. What do you need/want "DOM bindings" for?


As someone who would like to write his javascript in Haskell, how do you put text on the page without interfacing with the browser's DOM?


I'm curious about this as well so I did some searching.

Fay[1], a subset of Haskell that compiles to JavaScript, seems to be the primary choice. There are DOM and jquery bindings for it and this blog post[2] looks like a great introduction.

There are other options, this [3] article outlines a number of them as a greater overview of both server and client side programming with Haskell. I also found an intriguing article [4] on the Haskell site but it appears to be out of date, referencing libraries that are no longer in development.

[1]https://github.com/faylang/fay/wiki

[2]http://ocharles.org.uk/blog/posts/2013-12-23-24-days-of-hack...

[3]http://www.stephendiehl.com/posts/haskell_web.html

[4]http://www.haskell.org/haskellwiki/Haskell_in_web_browser


http://elm-lang.org/ for example. To display text in the browser you would use -

main = plainText "Hello, World!"

From the page: "Elm is a functional language that compiles to HTML, CSS, and JavaScript".

So yes, technically this is working with the DOM. But you are not writing code that interacts with a "DOM binding" directly per se.


I've played with Elm for a toy project before and I do have high hopes for it. I also think it's the greatest monad tutorial ever - you don't truly miss them until they're gone.

(To clarify: At the time that I last used Elm, the Signal type was a functor, but was intentionally being kept from being a monad for design reasons. Working around this restriction tought me a lot on why I needed monads.


I didn't really understand applicative functors until I was playing with Elm. Working with Signals was pretty fun, and when I found out they were applicative functors, it was like a light bulb going off above my head.

Elm is a really fun way to start exploring purely functional programming.


I'm excited for PureScript for the property that it compiles to sane javascript.

http://purescript.readthedocs.org/en/latest/intro.html#hello...


Awesome, had not heard of this project before! Thanks for sharing.


Is that a trick question? I don't know how or why you would try to do that.


I assure you that it's not a trick question, just a poorly worded one.

Imagine that I'm making a page that converts meters to millimeters. The obvious part of the haskell code is

convert :: Double -> Double convert = 1000 *

The part which isn't obvious to me is how I get input from the user or display the result. I know how to do that in the IO monad through standard haskell, but I wouldn't know how to handle it in Haskell compile to javascript for the web browser. I would have thought that you would need a binding to the DOM to read from forms and the like.


I think fay uses its own FFI, but with haste you just use the normal FFI to call normal javascript functions the same way you would interface with C code from haskell. There's no need for special bindings or anything. You could certainly make a wrapper for jquery if you were crazy (and I'm sure someone has already done so), but this idea that you need some special DOM library to do things that javascript already does out of the box is kinda odd.


Thanks for the clarification. The key part that I was missing was the FFI. I'd encountered projects like this in the past with either no FFI or no documentation for the FFI and I couldn't figure out how to talk to the DOM. I'm more than happy to drop down to javascript for those parts, but I wasn't sure that I'd have the option.


You do it all the time in web apps. For example, changing the text of a toggle link between "show" and "hide." For example, with jQuery:

  $('#toggleLink').click(function() {
    if ($('#toggleLink').html() == 'Show') {
      showRollout();
      $('#toggleLink').html('Hide');
    } else {
      hideRollout();
      $('#toggleLink').html('Show');
    ]
  });


I think you misread something. He asked how to do it without manipulating the DOM.


Felix is to C++ what F# is to C# http://felix-lang.org/share/src/web/tut/tutorial.fdoc (I am not the author, just excited about this language) OCaML programmers will feel immediately at home.

It is a mature yet actively developed whole program optimized, strongly typed, polymorphic, ML like language that can interact effortlessly with C and C++ and has coroutines and threads baked in, although use of threads is somewhat discouraged. It has type-classes as well as modules. Functions written in it may be exported as a CPython module. This might be useful if one wants to gradually transition from a Python based src tree.

It uses a mix of lazy and eager evaluation for performance and compiles down to C++. Execution speed is comparable to hand written C++, mostly better. Its grammar is programmable in the sense that it is loaded as a library. So in the same way that languages may acquire libraries, Felix may acquire domain specific syntax.

It is also mostly a one man effort but with a feverish pace of development so it comes with its associated advantages and disadvantages.

Tooling info is here http://felix-lang.org/share/src/web/ref/tools.fdoc

The author likes to call it a scripting language but it really is a full-fledged statically compiled language with a single push button build-and-execute command. http://felix-lang.org/ The "fastest" claim is a bit playful and tongue in cheek, but it is indeed remarkably fast.


AFAICT you mention Felix whenever OCaml comes up, generally saying more or less the exact same thing each time.


Absolutely correct, and for F# too. I do want to get the word out, it really needs some love and eyeballs, but perhaps I overdo it.


Have you actually used Felix? I agree it's a neat language but it felt to me like I'd really have to come up to speed on C++ to make much use of it. It's "FFI" is basically embedded strings of C++ source.


You can of course inline C++ snippets in Felix code as you mentioned, but that is not the only way to talk to C++. Felix allows you to create a Felix object from a C++ object (and the reverse) with minimal glue. Take a look here http://felix-lang.org/share/src/web/tut/cbind_index.fdoc.

With this two styles the boundary between Felix and C++ can be very fluid. It does not incur the typical efficiency hit of a dynamically loaded FFI, although it does allow dynamically loading shared libraries too.

If you dont want to use C++ libraries and classes from Felix, you dont need to know C++ to use Felix.


If ocaml is a language waiting for a killer app, this might be it: http://www.openmirage.org/

There was a presentation at the FP eXchange in London last Friday about mirage and many a mind was blown!


Haskell also has the analogous HaLVM: https://github.com/GaloisInc/HaLVM


I really hope such systems take up, as we need OS designed with better languages.


I've found it interesting that OCaml hasn't had more interest given the amount of recent momentum in Haskell.

Haskell is an Ivory Tower. The features that generally draw one to the language also tend to be the things that eventually push one away. Haskell has grown a lot over the years however as the language evolves to allow general programming within a pure framework.

OCaml on the other hand tends to make a compromise, acknowledging that the programmer occasionally needs a different tool for the job. OCaml allows the programmer to opt into things like mutability and objected oriented code when the need arises. These compromises can also be seen as the languages downside however.

I find it interesting that the driver for the author into OCaml is JavsScript... but it's nice to see OCaml come up a bit more often. :)


I feel it's similar to any competitive environment: differentiation requires making strong tradeoffs. Haskell's choice of tradeoffs---while initially very ivory tower---have led to to become a strongly differentiated language. You not only learn how HM typing and full commitment FP feel, but also how to structure code purely, compose effects, and abuse laziness.

So for the very same reasons you give---Haskell has made fewer tradeoffs for "practical" programming---Haskell has become something valuable and interesting. On those tides the community has grown.


Another big obstacle was that the INRIA license effectively prevents forking the language (you can only distribute modified compilers as original source + patch, not as eg a github repo) so for a long time there was a bottleneck on the language evolution. Lots of useful extensions (eg delimited continuations, staging) wilted and died because of that.

The rise of OcamlPro and Ocaml Labs does give me hope for the future of the language. There is already renewed momentum behind fixing packaging and handling multicore.

Now if someone would just figure out ad-hoc polymorphism (just pick one of the dozens of propasals) and maybe even document camlp4/5....


I have to admit JavaScript isn't the only driver for my interest in OCaml. It is however the angle I'm pushing for using it in my day job :)


You are acknowledging that you are wrong without even noticing. No, haskell is not an "ivory tower". It is a very practical, useful language. That is precisely the reason it has gained so much momentum and usage. Ocaml had more users than haskell back in the mid 00s. Now haskell absolutely dwarfs ocaml. The reason ocaml doesn't get more interest pigging backing off of haskell is that there is no reason to use ocaml over haskell.


So maybe "middle of the road" and "pragmatic compromises" are overrated.


For me Scala has been the not-quite-as-good-as-haskell-but-more-industrially-acceptable language. I'd be very interested to see a more neutral comparison of functional languages for compile-to-JS, because if anything Haskell seems more popular for that - I hadn't heard anything about compiling OCaml to JS before this.


I just started at a Microsoft shop a few months ago (first time for everything), and I actually quite like F#, now that I've had a little while to play with it. It's a good contender for the NQAGAHBMIAL throne.

Having used CMUCL/SBCL for a while, I always found ocaml's "well, you can compile your code, but then you can't run it in the REPL" to be off-putting. (For my purposes the CLR JIT compiler for F# is good enough.)


Posted 20 minutes ago, and this post already shows up when you google "NQAGAHBMIAL". Impressive...


And now yours. And nothing else.

Is it "not quite as good as Haskell but maybe it's alright language"?


From the parent, "not-quite-as-good-as-haskell-but-more-industrially-acceptable language". Not intending to be obscure.


I've put a lot of work into a compile-to-JS evaluation for my day job. It's not suitable for public consumption, but of our top 5 choices:

- both Kotlin and ClojureScript don't compile code written in their "native" language (java) to JavaScript, limiting the ability to leverage existing libraries. - ScalaJS is still experimental. - Haskell looked promising, I asked a haskell programmer to run that evaluation for me, but fay/haste aren't complete enough for serious (non-ui) JavaScript work and GHCJS generates 5mb JS files. - OCaml had a viable project in about half the time I estimated it would take.

And on a personal note, Scala seemed great at first but after SML/OCaml I find the number of times that I have to tell the type checker what I'm doing immensely frustrating :)


Did you examine Ceylon? It seems to avoid the problem you describe with Kotlin and ClojureScript by explicitly abandoning the Java native library.


I haven't, no. We excluded the vast majority of AltJS languages as the size of community and availability of third-party libraries was a significant factor in the evaluation.


Having had Camllight as my first functional language, ML language family got a special place on my heart.

I have three issues with Scala:

- Having to wrap free functions in objects

- I feel Haskell type system is easier to understand than Scala's

- The concept of open and closed case classes for sum types feel wrong

So in the end I actually enjoy more using F# in general, and Clojure when targeting the JVM.

Now back to reading "Real World OCaml". :)


What are you mean at "not-quite-as-good-as-haskell"? What are the killer features of haskell?


Not the original commenter but for me the big ones are purity and cheap direct access to C code.


You can program in pure mode in scala too(and scalaz framework helps in it). FFI is great but i don't miss it. For better performance there is the java collections and libraries.


Scalaz helps with the idioms but without the purity garuantees you miss out on all the optimizations and verifiability.

The java collections & libraries don't help me when I need to manage my own memory. I've spent entirely too much time in the unsafe package because the JVM doesn't allow me to do cheap ffi unlike Haskell or even Microsoft's CLI.


OCaml is actually taught in the second level computer science course at my university. I think its a great language for learning topics like recursion especially with its pattern matching. Its also a great intro to functional programming


This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line.

The only real reason that I can see to choose OCaml over Haskell is that if you learn OCaml, you might be able to work at Jane Street. Is there a strong argument for abandoning my Haskell-ing for OCaml?


> This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line.

That's easily fixed: only the toplevel requires ;; (to commence evaluation of the phrases you've typed in). Just don't use it in normal code and everything will parse fine.


> everything will parse fine.

That's an exaggeration. There are circumstances in files where it's necessary. I didn't realize this, which hung me up for a long time.


Would you care to share an example? I've never encountered a justifiable need to write ;; outside the REPL. The only uses of ;; I've encountered "in the wild" were hardly reasonable: essentially top-level code that was not wrapped in a "let () = ..." statement.


I don't recall seeing that recommendation before this thread. That may just be my blindness in skimming things too quickly. In any case, I think it indicates a wart in the language when you have to wrap everything in otherwise useless let blocks just to get it to parse.


Don't put non-let expressions at the top level?


;; is a special token used only in the REPL to force evaluation, it is not something you ever use in real code.


Well, that explains a lot! I'm embarrassed I never got past that.


Don't feel too bad about it. The official OCaml tutorial is also confused:

http://ocaml.org/learn/tutorials/structure_of_ocaml_programs...

(someone really should go through these tutorials and fix the various misleading parts)

Basically, the rule is to use "let () = ..." for your main block / top-level code and don't use ";;" ever.


For reference, here is the tutorial's example reformatted in a more reasonable way:

    open Random
    open Graphics

    let rec iterate r x_init i =
        if i = 1 then x_init
        else
            let x = iterate r x_init (i - 1) in
            r *. x *. (1.0 -. x)

    let main () =
        self_init ();
        open_graph " 640x480";

        for x = 0 to 639 do
            let r = 4.0 *. (float_of_int x) /. 640.0 in
            for i = 0 to 39 do
                let x_init = Random.float 1.0 in
                let x_final = iterate r x_init 500 in
                let y = int_of_float (x_final *. 480.) in
                Graphics.plot x y
            done
        done;

        ignore (read_line ())

    let () = main ()


The trouble with Ocaml is that you will probably get something like:

  $ ocaml o.ml
   File "o.ml", line 2, characters 0-13:
   Error: Unbound module Graphics
And after you've googled for a while and had done:

  sudo apt-get install liblablgl-ocaml-dev
The thing would install 23(!) packages. And after that you will get:

  $ ocaml o.ml
   Exception: Graphics.Graphic_failure "fatal I/O error".
After which, if you've been in the industry for a decade or two, you will probably decide that you'd better stop wasting your time on that particular language. Besides. It just looks ugly. Almost as ugly as perl.


The Graphics module is a core Ocaml library that is always available. In order to use it, it must be linked on the command line, similar to many other languages. Installing an unrelated OpenGL binding didn't magically make "ocaml o.ml" work. Based on this and the obvious trolling of your final paragraph, I'm hesitant to believe anything you said is true.


Seriously. You are so biased that it is easier for you to believe that other people are downright lying than to accept inconvenient truth. I was running it in the interpreted mode. Isn't that how one is supposed to run tutorials code? And obviously I've added the following:

  #load "graphics.cma";;
into the file first. And forgot about it, when writing the post. So no magic here. "Beautiful" syntax by the way.

And no, I wasn't trolling. I just wanted to see what that recursion would do. The code is not exactly crystal clear there, with names like start_x and such. But it really did not work. And the syntax is really ugly. And you can believe what you like.


Dont judge syntax when you are new to a language. Few syntaxes have the tendency to never grow on you, but it is surprising how most do, even when your first impressions were pretty bad. Remarkable abilities of the human brain !


Does that mean that K syntax could grow on me? http://en.wikipedia.org/wiki/K_(programming_language)

For this old C programmer, Python proved to have the most friendly syntax.


Tried it here and it worked, both on Arch Linux with OCaml 4.01.0 and a clean Ubuntu/12.04 with OCaml 3.12.1:

$ ocaml graphics.cma test.ml

Debian splits OCaml into two packages: ocaml-nox (no X) and ocaml (everything). Make sure you're not using the nox version, and make sure you have an X server available (i.e. you're not running it on a headless server or something).

Still, "fatal I/O error" is a terrible error message.


Ocaml 3.12.1; Ubuntu 13.10. X server is available, Desktop is MATE 1.6.0, OpenGL also seems to work (glxgears works).



OCaml is Object Caml right? What about SML? I always loved SML, but it never got any traction at all. The O in Ocaml always turned me off, they cluttered up the syntax with all the object notation.

Does anyone have any insight into why OCaml rose to (relative) prominence and not SML?


Ocaml was always the more pragmatic language and for a long time the implementation was significantly faster than anything SML offered. MLton came along very late in the game and offers excellent performance, but doesn't support separate compilation.

Edit: A more lengthy comparison: http://adam.chlipala.net/mlcomp/


Thanks for the perspective!


For me (the author), it's because SML as it was taught to me is a closed language. It can never and will never change. Perfect for education, perhaps not so useful as a career choice.

OCaml has been moving forward; GADTs were added recently, multicore support is coming, and who knows what else is on the horizon.


what saddens me is that aliceml [https://www.ps.uni-saarland.de/alice/] seems to have died. i've kept it vaguely in the back of my mind as "this looks like a very pleasant language, and as soon as i have a problem in its sweet spot i'll give it a good look", but the last time i went to look at it i realised the last mailing list post was in 2012, and the last home page update in 2007.


Considering how strongly opposed the author is to dynamic typing, I'm actually kind of surprised they'd consider OCaml's type system to be acceptable.

Technically, yes, it's a statically typed system. But its use of structural typing instead of nominative typing effectively means it takes half the compiler assistance you can get out of static type checking and chucks it out the window. Using structural typing means that a type is nothing more than the sum of its parts; nominative typing makes it possible to add further specificity to types by naming them. This is huge. A language that doesn't do this is a language that can't be taught to understand the difference between 12 meters and 12 Newtons.


You may be confused by the fact that the type system will notice the equivalence of two types if the implementations of both are public eg

    module M = 
    struct
       type newtons = int
       let inc some_newtons = some_newtons + 1
    end :
    sig
       type newtons = int
       val inc : newtons -> newtons
    end

    M.inc 1 (* this works *)

    module M = 
    struct
       type newtons = int
       let inc some_newtons = some_newtons + 1
       let in_newtons x = x 
    end :
    sig 
       type newtons
       val inc : newtons -> newtons
       val in_newtons : int -> newtons
    end

    M.inc 1 (* type error *)
    M.inc (in_newtons 1) (* this works *)
The use of hidden types in OCaml gives far better control over encapsulation and implementation hiding than any over language I've used.


Abstraction provides the equivalent of nominative typing. It is easy to differentiate between 12 meters and 12 Newtons with OCaml's type system.

In general, it is easy to get nominative behaviour out of a structural system. It is much harder to get structural behaviour out of a nominative system.


Also, only some things in OCaml are structurally typed (modules, objects, polymorphic vairants), others are not (records, variants). For example:

    # type meters = I of int;;
    type meters = I of int

    # let meters i = I i;;
    val meters : int -> meters = <fun>

    # type newtons = I of int;;
    type newtons = I of int

    # let newtons i = I i;;
    val newtons : int -> newtons = <fun>

    # let f b = if b then newtons 12 else meters 12;;
    Characters 36-45:
      let f b = if b then newtons 12 else meters 12;;
                                          ^^^^^^^^^
    Error: This expression has type meters but an expression was expected of type
             newtons


>But its use of structural typing instead of nominative typing effectively means it takes half the compiler assistance you can get out of static type checking and chucks it out the window

It is quite rare for people to use objects in ocaml anyways, so it doesn't matter much.

>A language that doesn't do this is a language that can't be taught to understand the difference between 12 meters and 12 Newtons.

Sure it can. Make a type for meters and a type for newtons. Haskell won't think there is a difference between those if you make them both an int either.


"...Facebook created ... a statically typed PHP variant..." - so happy to see another major tech company understand the merits of static typing.


that's because PHP is such a horrible language you need static typing to make sense of the crap. </snark>


Agree, same true for JS - so many people trying to fix the mess...


... and so sad about them further fragmenting the ecosystem with yet another language.


How do those "to js" code generator behave when used together with frameworks like backbone or angular ?

I know things like typescript or dart have special versions of the framworks, but i'm curious to know how the ocaml to js tools behave ( since i've searched for a decent strongly typed server side technology for years, that would be an argument for me to try that language).


I don't know about OCaml, but generally speaking, there is a foreign function calling interface. You'd typically use it for integrating with large standalone codebases you don't want to rewrite (say, CodeMirror) but typically not for frameworky things. If you're going to use the same UI framework there's not much point in switching languages.


OCaml has quite nice JavaScript integration; it has the ability to interact with JS objects, constructors, DOM objects, etc. See the "dom bindings" thread elsewhere in this discussion.

Most other AltJS languages I've seen are primarily based around FFI declarations, where all interaction with JS is done via functions declared in the native language as external and implemented in JS.


Here's the plan -- eliminate perl, python, ruby, php or java or any slow-starting jvm-based language(the featureless landscape of clojure for example), and use just bash, sed, awk, ocaml(to replace the fear of 'C'), and we can also do f# on windows, so there would be crossover between the worlds and peace throughout the land.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: