this post was submitted on 04 Feb 2024
12 points (100.0% liked)

Functional Programming

1389 readers
1 users here now

founded 1 year ago
MODERATORS
 

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?

top 8 comments
sorted by: hot top controversial new old
[–] [email protected] 3 points 9 months ago (1 children)

OCaML is an amazing language to explore type arithmetic and type based programming. CaML in general is famous for its type flexibility.

[–] [email protected] 1 points 9 months ago (1 children)

Is there a CaML worth exploring/using other than OCaml?

[–] [email protected] 2 points 9 months ago

CaML is more functionally pure but I think OCaML is generally more useful. I'd suggest just focusing on OCaML.

[–] [email protected] 2 points 9 months ago

Modules. I find they're a really great to organize code, and a lot of Ocaml code out in the wild use them.

[–] [email protected] 1 points 9 months ago (1 children)

If you want to read some monads in the wild, go check the code for Jane's Street "core_unix.command_unix"

Otherwise, GADT, but they are used sparingly because they make type inference undecidable

[–] [email protected] 1 points 9 months ago (1 children)

Ahh I see, so Monads are not that great for Ocaml then?

What's the best way to handle side effects? I suppose one way is to reduce the amount of code using them. Is there a better approach?

[–] [email protected] 1 points 9 months ago

I would be lying if I said that I was a professional Ocaml developer.

I do definitely think the Jane's library is very hard to read... But that might be my inexperience

I personally think regular, procedural code is much easier to read ¯_(ツ)_/¯

[–] [email protected] 1 points 9 months ago

I've never had a chance to try it, but formal verification with Coq always looked really interesting.