DEV Community

8 months of OCaml after 8 years of Haskell in production

Dmitrii Kovanikov on December 16, 2023

I've been using Haskell in production for 8 years. I've been using OCaml in production for 8 months. It's time to compare those two languages. ...
Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
chshersh profile image
Dmitrii Kovanikov

Thanks! I hope you enjoyed your time at Bloomberg 🤗

Indeed, this particular example could be written better with the usage of pattern matching. I wanted to show the difference between guards and if-then-else. But looks like this particular example is not that convincing.

I'll change it to a better one when I come up with it!

Meanwhile, you might have some other example in mind?

Collapse
 
yawaramin profile image
Yawar Amin

If we are comparing succinctness, let me offer an alternative parsing example :-)

let parse_line line =
  Scanf.sscanf line "Status: %d | Result: %d" (fun status result ->
    if status = 0 && result mod 2 = 0 then Some result else None)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
chshersh profile image
Dmitrii Kovanikov

Good example! I often forget OCaml has sscanf too as well as printf 😅

Collapse
 
dmbaturin profile image
Daniil Baturin

To.ml: A TOML parser

I was so infuriated by that library that I made one to fix all its problems. ;)
github.com/dmbaturin/otoml/

It's actually compliant with the TOML standard, uses transparent types (but also offers helpers for getting nested values), and uses functors to allow the user to plug any datetime and bignum libraries or stick with built-in native int and string dates.
Well, and offers informative parse errors, too.

Collapse
 
chshersh profile image
Dmitrii Kovanikov

Hey @dmbaturin

I was informed that ez_toml is better than otoml:

discuss.ocaml.org/t/8-months-of-oc...

Do you have a comparison with this library somewhere?

Collapse
 
chshersh profile image
Dmitrii Kovanikov

Thanks for letting me know! Your library looks great, I'll update the link 🔗

Collapse
 
fluffy8unny profile image
ふわふわのうさぎ

I follow you on twitter and saw your recent posts about ocaml, so I decided to actually try it out. Using it for a bit during the holidays made me feel like it's just worse Haskell. When I saw your post, I thought that I'd see some features that are amazing, while it might just be my viewpoint, the stuff you're showing me here makes me want to use Haskell even more.
Less than language features a few of the libraries are really cool tho. I'd love to have something akin to owl (cl.cam.ac.uk/~lw525/owl/chapter/pl...)

Collapse
 
chshersh profile image
Dmitrii Kovanikov

It's totally fine to have different preferences!

If you enjoy using Haskell, you can continue using it 🤗

Collapse
 
doby profile image
Escherial

You forgot the best asset OCaml which is its Web framework. Ocsigen is the most advanced web development framework. It's revolutionary once you get how it works. Nothing else can compete, in any language.

Collapse
 
chshersh profile image
Dmitrii Kovanikov

I never tried Ocsigen. I guess, it's hard to compare two languages fully because you can never try everything.

But you reply gave me some motivation to try it 👀

Collapse
 
zeta611 profile image
Jay Lee

I’ve been using OCaml for 4 years now, but never used Ocsigen for web development. I have some experience with ReScript with React tho. I’m really curious about using OCaml for both front/backend; why would you recommend Ocsigen (vs something like Dream)

Collapse
 
bitmaybewise profile image
Hercules Lemke Merscher

Awesome post!

I tried OCaml many years ago. I think around the same time I started playing with Haskell, but gave up on OCaml due the fact that Haskell felt more pleasant to use. You definitely made me wanna try OCaml again :)

Collapse
 
chshersh profile image
Dmitrii Kovanikov

I'm glad my post was inspiring enough 😊

Collapse
 
chshersh profile image
Dmitrii Kovanikov

I received tons of feedback on my OCaml vs Haskell blog post! Thanks a lot to all who read and shared their thoughts 🤗

Using the feedback, I improved my post by:

✍️ Changing the most triggering exponentiation example to a different one
✍️ Added links to all discussions of my blog post all around the Internet
✍️ Changed feature from 'Laziness by default' to 'Composable laziness'
✍️ Added 'topiary' as an OCaml formatter
✍️ Changed the suggested TOML library from 'To.ml' to 'otoml'
✍️ Changed the suggested AWS library from 'ocaml-aws' to 'awsm'

Hope you enjoy it!

Collapse
 
bartlisa profile image
Bart

Terrific post!

For the comparison table, possibly include records support. This has been a Haskell deficit for decades, and no thank you, lenses are a bloated, heavyweight bolt-on when you just want simple, lightweight record support.

Collapse
 
chshersh profile image
Dmitrii Kovanikov

Thank you!

Haskell kinda has a better record story nowadays. You can actually have nice records in Haskell without using lenses!

Collapse
 
etorreborre profile image
Eric Torreborre

Nice article. It's great to have the two languages side by side as I'm tempted to have a closer look at OCaml.

Collapse
 
chshersh profile image
Dmitrii Kovanikov

Thanks!

Yes, I really wanted to compare these two languages.

You can find other blog posts comparing Haskell and OCaml (some are older, some are newer). But I wanted to provide my take anyway and share my experience 😌

Collapse
 
theoddler profile image
Pablo Bollansée

Great article! Really nice to see you're enjoying OCaml, I've been looking at it too, but have not actually used it yet, but this makes me even more interested in trying it out.

Collapse
 
chshersh profile image
Dmitrii Kovanikov

Thanks a lot, Pablo!

If you liked Haskell, I think you'll enjoy OCaml too 🙂

Collapse
 
tonyalaribe profile image
Anthony Alaribe

Lovely article! I look forward to trying out ocaml as well.
It's tradeoffs seem a lot like Go. Fast compile times, minimal syntax and moving parts,

Collapse
 
chshersh profile image
Dmitrii Kovanikov

Thanks! I think you'll enjoy OCaml 🤗

I do see it like Go of FP languages. Which is kinda the best of both worlds 😉

Collapse
 
renatillas profile image
re.natillas

Nice article, now I have a bigger picture of Functional Languages!

Collapse
 
chshersh profile image
Dmitrii Kovanikov

I'm glad I was able to help with my article! 🙌

Collapse
 
giullianosep profile image
Giulliano Ferreira

Great post! I'd like to see another comparison including F# as well.