7 OCaml Gotchas
Dmitrii Kovanikov

Dmitrii Kovanikov @chshersh

About: I'm a Functional Programming enthusiast and Senior Software Engineer at Bloomberg using OCaml at work. All opinions are my own.

Location:
London, UK
Joined:
Mar 7, 2023

7 OCaml Gotchas

Publish Date: May 20 '24
10 7

This article was permanently moved to my personal website:

Comments 7 total

  • Kakadu
    KakaduMay 20, 2024

    Gotcha 3 is actually a warning.
    Also, deciphering severity from the icons looks complicated.

    • Dmitrii Kovanikov
      Dmitrii KovanikovMay 20, 2024

      Gotcha 3 is actually a warning.

      Indeed, it's a warning. Still, I found this behaviour surprising, and decided to describe it in my blog post 😌

      Also, deciphering severity from the icons looks complicated.

      I don't think it's critical for the blog post understanding. Just a little extra from me to make the text less boring.

      My idea was:

      • 🍹- chill, not really important
      • ⚠️ - warning, you may have potential problems
      • 💀 - something really dangerous can happen
      • Kakadu
        KakaduMay 20, 2024

        In this case gotcha 6 has severity too high

  • Juneyoung Lee
    Juneyoung LeeMay 20, 2024

    For gotcha 2 you can use begin..end. Something like this:

    match .. with
    | ... -> begin match .. with ... end
    
    Enter fullscreen mode Exit fullscreen mode
    • Cyril
      CyrilMay 21, 2024

      You can also directly match the reason part in Pending. Not always practical, but in your example, I might have written:

      let show_status status =
        match status with
        | Cancelled -> "Cancelled"
        | Done -> "Done"
        | Pending Waiting -> "Pending: Waiting"
        | Pending Validating -> "Pending: Validating"
      
      Enter fullscreen mode Exit fullscreen mode
  • Yawar Amin
    Yawar AminMay 20, 2024

    Alternatively, you can use the local open syntax:...Book.(book.words) >= 50000

    You can also prefix the field name with its module: book.Book.words >= 50_000 ;-)

  • yami-no-ryuu
    yami-no-ryuuMay 21, 2024
    1. Labelled and Optional Arguments There's another gotcha, way worse. Partial application of such a function is hell on earth :( (ie type inference support is half there)
Add comment