from Hacker News

What I wish I knew when learning OCaml (2018)

by cribbles on 4/30/22, 9:28 PM with 86 comments

  • by bmc7505 on 5/3/22, 12:33 PM

    ML really is a beautiful and under-appreciated family of languages. Haskell is a bit too supernatural for my taste, but ML and its derivatives hit the sweet spot between powerful type systems and natural syntax. As a Kotlin developer, I find reading OCaml code a breeze and the compiler is refreshingly snappy (much faster than Gradle). I just wish it had better developer tools.
  • by pmoriarty on 5/3/22, 9:34 AM

    I tried OCaml a long time ago, and one of the things that really turned me off of it was all the inscrutable error messages. I went to #ocaml on Freenode for help, and when I had the error messages explained to me I asked how the person who explained them knew what they meant. He told me that the reason he knew was because he took a couple of semesters of type theory courses at his university. I didn't want to have to take a couple of semesters of type theory courses in order to be able to program effectively in this language. I hope the situation has improved since then.

    The other thing I didn't like (which was something shared with other statically-typed languages) was feeling like I had to wrestle forever with the compiler to get my program to run. It just always felt so much easier to write programs in dynamically typed languages. Sure, my programs might have bugs in them, but I could iron them out over time, and my programs change so much anyway that pieces of buggy-but-working code in those dynamically typed languages might be replaced wholesale anyway before I even ran in to the bugs.. so the pace of prototyping in dynamically typed languages is much faster, in my experience.

  • by dgan on 5/3/22, 9:54 AM

    TIL that Ocaml/SML are compiled into lambda expressions... I literally thought lambda calculus is only used in CS classes.

    OCaml's syntax is pretty annoying but type inference is actually amazing.. I changed my mind over it, as previously I thought explicit type annotations are simpler. Turns out, it would be humanly impossible to explicitly annotate every piece of OCaml, just let the compiler do it for you

  • by pharmakom on 5/3/22, 9:17 AM

    A good list. ML languages push you (kicking and screaming) into the pit of success.
  • by baby on 5/3/22, 11:11 AM

    shameless plug: learn with ocaml by example[1]. It is still heavily work in progress though, please feel free to create a PR :)

    [1]: https://o1-labs.github.io/ocamlbyexample/

  • by cassepipe on 5/3/22, 11:33 AM

    Could someone please explain ? : type 'a list = 'a :: 'a list | []

    The article says "::" is a Data Constructor. I can make sense of type 'a = Left of 'a | Right of 'a where Right and Left are the Data constructors but I don't see the link with the part I don't understand.

  • by shikoba on 5/3/22, 12:36 PM

    The golden rule is missing:

    > Don't try to understand the error message except if you have no other choice.