this post was submitted on 02 Apr 2024
142 points (98.6% liked)
Programming
17494 readers
37 users here now
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
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
What's so special about Ocaml's type system?
I won't remember everything, but one very important things comes to mind:
in Typescript, it is very difficult to assert on a type (let me know if you're not familiar with what I mean by this and I can explain further). In OCaml, this is trivial using pattern matching.
Why would you need that? The idea of a type system is it doesn't let you apply a function on a structure without the structure being of the right type. But the lack of type assertion in TS makes people follow hacky workarounds, which defeat the purpose of type system.
There are a couple of other things, like immutable types by default, automatic tail call optimization, functors enabling higher kinded types, etc.
Also in ocaml, you don't have to annotate any types on any variable or parameter, and you'll still get full type protection.
Oh, so what you're describing is strong typing. I thought it was a unique feature of Ocaml. But in reality, any strong-typed language will have this as well.
And yeah, Typescript merely "suggests" typing, and it will allow you to build the project even if you ignore the type errors. A build system refusing to, well, build, if there are typing errors usually takes care of this, but again, the dev team may as well not implement this.
Any examples other than ocaml? From my understanding, ocaml's type strength may only be found in a couple other languages. Haskell, scala, and maybe Rust. Any others?
I thought of Pascal, Java and C#, but pretty much any language listed here as "explicit / nominal / static" makes the cut:
https://en.wikipedia.org/wiki/Comparison_of_programming_languages_by_type_system