cross-posted from: https://lemy.lol/post/19181146

I just started to learn Ocaml to learn functional programming. I will use it to build a CLI that’s mostly orchestrating other programs.

My experience is mostly in JS / TS, but I’ve also coded a good bit in Python and Lua.

Below, I provided a list of things I learned or focused on while using OCaml. But I feel like I must be missing something. This is only moderately different from what I’m used to in JS. I expected something more radical. Moreover, I constantly hear a lot of FP jargon (like “highly kinded types”, monads, etc) that I feel am still missing.

So far, here’s what I studied:

  • immutability
  • avoid side affects
  • static typing
  • recursion instead of loops
  • option / maybe
  • higher order functions
  • conditionals and other constructs as expressions, when they’re statements in other languages
  • pipelines and functions as input —> output
  • currying
  • scoping with let

What am I missing?

Algebraic datatypes is a huge part of typed functional programming for me, you should read up on that!

pinchcramp
link
fedilink
3
edit-2
7M

For the jargon part: See this Github repo. It ain’t exhaustive, but it’s a start.

Other than that, all I have to add is that functional programming does not necessarily imply static typing. There is a whole world of Scheme-variants that are dynamically typed.

@solrize@lemmy.world
link
fedilink
6
edit-2
7M

The jargon you mention is mostly associated with Haskell so you might want to study that too. It has a steeper learning curve but will expand your mind more. Ocaml is great but it’s more like what you are used to, especially if you’re comfortable with TS. Missing from your list is Ocaml’s module system which is more serious than Haskell’s, so you should spend some time on it.

For Haskell, see the online books learnyouahaskell.com and https://book.realworldhaskell.org/ . Both of those are now kind of old, but will get you started. Edit: realworldhaskell link fixed.

@matcha_addict@lemy.lol
creator
link
fedilink
37M

My fear with Haskell is that I will end up trying to learn category theory, which will be a much bigger time sink. But I suppose it is the natural next step.

Thanks for the pointer on the module system! I’ll study that next.

CT as used in Haskell isn’t a big deal. I found that it demystified a lot so was worth looking into, but really, it’s optional. This tutorial is good:

https://en.wikibooks.org/wiki/Haskell/Category_theory

Even more optional, after the above try this:

https://www.haskellforall.com/2012/08/the-category-design-pattern.html

Whatever you’re not familiar in the digital textbook OCaml Programming: Correct + Efficient + Beautiful

There’s a whole chapter on modules

There’s also a section on Monads

You should also know that there is a schism in OCaml ecosystem created by the libraries developed by Jane Street and the those developed by INRIA.

@matcha_addict@lemy.lol
creator
link
fedilink
17M

I did see the Jane street stuff. Is it better to use them instead of the standard library?

I don’t know if one is better than the other, but knowing that certain libraries are incompatible based on this bifurcation is a good thing to remember.

Create a post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



  • 1 user online
  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 1.11K users / 6 months
  • 1 subscriber
  • 1.21K Posts
  • 17.8K Comments
  • Modlog