Dmitrii Kovanikov Posted on May 20, 2024 • Edited on Nov 30, 2024 7 OCaml Gotchas #ocaml #functional #programming #beginners This article was permanently moved to my personal website: chshersh.com :: 7 OCaml Gotchas Top comments (8) Subscribe Submit Preview Dismiss Collapse Expand yami-no-ryuu yami-no-ryuu yami-no-ryuu Follow Joined May 21, 2024 • May 21 '24 Dropdown menu Copy link Hide 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 Expand Yawar Amin Yawar Amin Yawar Amin Follow Joined Jun 11, 2017 • May 20 '24 Dropdown menu Copy link Hide 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 Expand Kakadu Kakadu Kakadu Follow Joined May 20, 2024 • May 20 '24 Dropdown menu Copy link Hide Gotcha 3 is actually a warning. Also, deciphering severity from the icons looks complicated. Collapse Expand Dmitrii Kovanikov Dmitrii Kovanikov Dmitrii Kovanikov Follow I'm a Functional Programming enthusiast and Senior Software Engineer at Bloomberg using OCaml at work. All opinions are my own. Location London, UK Education ITMO University Pronouns he/him Work Senior Software Engineer at Bloomberg Joined Mar 7, 2023 • May 20 '24 Dropdown menu Copy link Hide 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 Expand Kakadu Kakadu Kakadu Follow Joined May 20, 2024 • May 20 '24 Dropdown menu Copy link Hide In this case gotcha 6 has severity too high Collapse Expand Juneyoung Lee Juneyoung Lee Juneyoung Lee Follow Joined May 20, 2024 • May 20 '24 • Edited on May 20 • Edited Dropdown menu Copy link Hide For gotcha 2 you can use begin..end. Something like this: match .. with | ... -> begin match .. with ... end Enter fullscreen mode Exit fullscreen mode Collapse Expand Cyril Cyril Cyril Follow Joined May 21, 2024 • May 21 '24 • Edited on May 21 • Edited Dropdown menu Copy link Hide 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 Collapse Expand André Borba André Borba André Borba Follow Software Engineer Email andre.borbaaf2b@gmail.com Location Brazil Work Software Engineer at PipoSaude Joined Aug 6, 2024 • May 12 Dropdown menu Copy link Hide you're amazing, Dmitrii. Code of Conduct • Report abuse
Top comments (8)
You can also prefix the field name with its module:
book.Book.words >= 50_000;-)Gotcha 3 is actually a warning.
Also, deciphering severity from the icons looks complicated.
Indeed, it's a warning. Still, I found this behaviour surprising, and decided to describe it in my blog post 😌
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:
In this case gotcha 6 has severity too high
For gotcha 2 you can use
begin..end. Something like this:You can also directly match the
reasonpart inPending. Not always practical, but in your example, I might have written:you're amazing, Dmitrii.