DEV Community

Dmitrii Kovanikov
Dmitrii Kovanikov

Posted on • Edited on

7 OCaml Gotchas

This article was permanently moved to my personal website:

Top comments (7)

Collapse
 
yaminoryuu profile image
yami-no-ryuu
  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)
Collapse
 
yawaramin profile image
Yawar Amin

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 ;-)

Collapse
 
kakadu profile image
Kakadu

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

Collapse
 
chshersh profile image
Dmitrii Kovanikov

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
Collapse
 
kakadu profile image
Kakadu

In this case gotcha 6 has severity too high

Collapse
 
juneyoung_lee_79db1f00801 profile image
Juneyoung Lee • Edited

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

match .. with
| ... -> begin match .. with ... end
Enter fullscreen mode Exit fullscreen mode
Collapse
 
cyril-allignol profile image
Cyril • Edited

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