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?

      • ericjmorey
        link
        fedilink
        arrow-up
        1
        ·
        10 months ago

        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.

  • solrize@lemmy.world
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    10 months ago

    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.

  • pinchcramp@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    10 months ago

    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.

  • zygo_histo_morpheus
    link
    fedilink
    arrow-up
    3
    ·
    10 months ago

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