Functional Programming in OCaml
cs.cornell.edu
cs.cornell.edu
They have used it extensively:
https://reasonml.github.io/blog/2017/09/08/messenger-50-reas...
With impressive results:
“ Messenger used to receive bugs reports on a daily basis; since the introduction of Reason, there have been a total of 10 bugs (that's during the whole year, not per week)! *”
Re: Mostly compatible: I remember there were certain things that were not easily expressible with Reason (but available in the OCaml syntax) a few years ago, not sure if it is still the case.
Subjective: OCaml syntax is definitely on the weird side, although I would not call it ugly. This coming from someone who enjoys writing clojure and xslt, go figure :-p.
1: https://github.com/facebook/reason/blob/master/src/README.md...
For example, it works well with Core_kernel [2] and Async_kernel [3] to provide high-level functionality that is cross compatible between Unix applications and browser applications.
[1] https://github.com/ocsigen/js_of_ocaml
But I think evmar's commits are just ninja commits. First BS commit: [3]. Almost looks as if the author of BuckleScript maybe forked the ninja repo and started to work in BuckleScript from there.
Why would anybody do that? Such a mystery...
1: https://github.com/BuckleScript/bucklescript/graphs/contribu...
2: https://github.com/ninja-build/ninja
3: https://github.com/BuckleScript/bucklescript/commit/a626ee8b...
In an absence of an entirely obvious, unambiguous, commonly known way of formatting, it's helpful.
As for formatting, if you manage to get an AST, what would be made easier by braces ?
If you already have a correct AST, you can render it whatever way you want.
https://en.wikipedia.org/wiki/Reason_(syntax_extension_for_O...
It would be quite awesome if they made it fully interactive; in the vein of several other textbooks that have been shared on HN recently.
—- Also, the responsive design of the book works pretty well on iOS, and that has been a rarity in this area from my experience.
[0] https://sicp.comp.nus.edu.sg/ [1] https://eloquentjavascript.net/
1. Download the OpenAPI Generator CLI Java JAR (https://repo1.maven.org/maven2/org/openapitools/openapi-gene...)
2. Rename the JAR as "openapi-generator-cli.jar"
3. Run the following command to generate an OCaml API client for the Petstore API (https://raw.githubusercontent.com/OpenAPITools/openapi-gener...):
Mac/Linux:
$ java -jar openapi-generator-cli.jar generate -g ocaml -i https://raw.githubusercontent.com/OpenAPITools/openapi-gener... -o /var/tmp/ocaml/
Windows:
$ java -jar openapi-generator-cli.jar generate -g ocaml -i https://raw.githubusercontent.com/OpenAPITools/openapi-gener... -o C:\tmp\ocaml
If you've any feedback or question, please let us know via https://github.com/OpenAPITools/openapi-generator/issues/new
I thought Standard ML had it in the 70's (!)
It's a bit sad that the foundations of modern programming languages were basically known by 1975 (either via Standard ML or Scheme) but the majority of languages in common use (mostly of a 1990s vintage) didn't learn those lessons. Thankfully that seems to be changing with more recent languages (Go being the exception).
Having researched a bit in the 60's and 70's systems programming languages, I would assert that the same issues with Go apply to C (language design vs existing competition), and they only got lucky because Bell Labs was forbidden to profit from UNIX.
I think i remember that there wasn't a good web framework, and that the existing popular one had a memory leak.
I was learning from a book (Real World OCaml, i think) and it kept pushing jane street libs like Async and Core.
Reason uses the OCaml to Javascript compiler Bucklescript to make OCaml more accessible for web programming. Listen to the podcast 'Reason Town' - https://player.fm/series/reason-town to hear professionals talking about their experience with it.
The issue with the web framework still stands. Not many people do web development in OCaml so the support is rather sparse.
* Ocaml has an extremely powerful module system that puts that of almost every other language, including Haskell's, to shame.
* Ocaml also has a very powerful object system that goes unused 95% of the time, but could potentially be useful for that other 5%; there's nothing comparable in Haskell.
* Ocaml has no ad-hoc polymorphism, whereas Haskell has typeclasses. The module system substitutes for this in many cases, but it's arguably less ergonomic. In other cases you just need to, say, use different operators to add floats than integers, which is definitely less ergonomic.
* Ocaml has comparable - probably superior - single-threaded performance (very good), but unlike Haskell there's no real parallelism story to speak of. Multicore support has been in the works for over five years and still hasn't arrived.
* Ocaml has a smaller community and ecosystem. Yes, smaller than Haskell.
* As a matter of personal opinion, I prefer Ocaml's straightforward and widely-loathed syntax to Haskell's weird, whitespace-sensitive one.
Subjectively, I think OCaml is a huge improvement over, say, Java, but if you’re deciding between learning one of OCaml or Haskell in 2020 I think Haskell is the better option for most people.
I think Haskell's a good way to start learning functional programming because it really beats the habit of loops and mutability out of you real fast by making the functional way easier. But if you're already an experienced FP programmer, less restrictive languages are better.
What makes Haskell interesting is all the crazy optimizations it can do since the compiler has so much information about the program. It would be really cool if other languages had a "pure" annotation or keyword that signified the function has a pure interface. This could dramatically improve the performance of a lot of Scala/F#/OCaml code.
> I've personally never found Haskell's encoding of mutability or impurity into the type system to be of any real benefit.
I find it completely indispensable for large codebases, especially codebases I didn’t write.
> Most of the time your impurity is coming from logging, networking, or interacting with files or a db; in which case, it's entirely obvious what's going on.
Maybe you’re a genius or something, but to me (and most people) it’s not “entirely obvious what’s going on” when large codebases use impure side-effectful semantics in a way that’s not clear from the types.
> Other times, you have a pure function that's implementation is unpure, which is also obvious on what's going on.
Once again, it is not at all obvious. And a very large fraction of the time, that “pure function with an impure implementation” isn’t actually so pure after all, and either leaks mutable semantics or behaves badly (e.g. if used in a multithreaded way). Haskell actually does have a real solution for this in the form of the ST monad. You can write impure things and prove (using the type system) that they have pure semantics. I’m not aware of any other language offering this.
> In any case, if you're programming in good FP-style all Haskell is providing is a bunch of headaches around finding the write way to make all your type annotations match up
Not only are type annotations optional (and usually trivial), but you can get the compiler to write them for you interactively e.g. with holes. In any case, this is never a problem in practice for “business logic” code. I’ve only really seen this come up e.g. when writing lenses by hand (i.e. rarely).
> it's kind of a annoying experience when you're just trying to get something done.
The point where the cognitive overhead introduced by Haskell’s type system is worth the payoff compared to, say, Python, is about 1-200 lines in my experience.
> But if you're already an experienced FP programmer, less restrictive languages are better.
The only “improvement” that you’ve cited so far is that “less restrictive languages” let the programmer be architecturally lazy, which I don’t think is really an improvement.
> It would be really cool if other languages had a "pure" annotation or keyword that signified the function has a pure interface.
If this were preferable, then Haskell programmers could just write everything in IO and selectively factor things out into pure functions. The fact that no one does this is, I think, telling.
For concurrency, LWT and Async are both mature and used in production.
That got a smile from me, given that OCaml is older than Java.