static typing is better but I'm not gonna tell anyone they're wrong for choosing dynamic typing. if they appreciated being told when they're making a mistake they wouldn't be using a dynamically typed language in the first place

@fool The only possible exception I've seen is ocaml, but it uses strict dynamic typing unlike every other language I've seen.


@RandomDamage @fool last time I checked, OCaml had static typing...

@wolf480pl @fool you don't declare the type, it detects it.

So you can declare a method to take a generic type and it will type check it against each call to that method.

@RandomDamage @wolf480pl lots of statically typed languages have type inference

@fool @wolf480pl ocaml is the only one I have experience with that has type inference and strict typing

@RandomDamage @fool
The reason OCaml is still a statically typed language is that it can give you errors at compile time.

A language with strong dynamic typing would instead throw an exception at runtime when you pass a wrong type.

@wolf480pl @fool um, why wait when you can detect the error at compile time?

@RandomDamage @fool
In static typing you can detect a type error at compile time.

This is true for OCaml, C, Java, etc.

@wolf480pl @fool right, but with ocaml it checks for type errors even when you have a generic method.

It checks *at compile time* whether a call to a class is type consistent.

Without declaring any of the classes involved in any of the variables.

Because it can (as could any other dynamically typed language that cared to)

@wolf480pl @fool [OK, I may have been sloppy in usage there. In my defense I'm 3 shots of rum into a Sunday evening]

@RandomDamage @fool
Yes, it doesn't need the type declarations to check types.

What I've been saying is, if the inferred type is what you want, you don't need the type declaration, but you may still want it as a form of documentation.

It checks them because it can, and because it was designed so that it can.
Not every language could, if it cared to.

@wolf480pl @fool true, but most of the languages that can check require the declaration to check.

OCaml is something of a unicorn in my experience, since it will check at compile time without any declarations anywhere.

@RandomDamage @fool
Haskell, Zig, and Rust AFAIK don't need type declarations most of the time either.
Also, the modern so called "C++" has grown an `auto` keyword which in many cases can be used for type inference as well...

Scala and Kotlin have type inference to some extent as well, from what I've read.

But yeah, for me too OCaml was the first language where I saw type inference at work.

@wolf480pl @fool I didn't find Scala's type inference as robust as OCaml's, but that's the only one of that set that I have much experience with

@RandomDamage @fool
Yes, this is static typing with type inference and generics.

Also, while I don't have to specify types in OCaml (and Haskell and the like) I usually do it as a form of documentation.

@wolf480pl @fool sometimes (a lot of times in my experience) you want a method that acts against a lot of different types consistently, *and* you want type checking as part of that

@RandomDamage @fool
Yes, hence generics.
And if I want it generic I do specify type a type parameter.

eg, if I want it to be generic:

first : 'a list -> 'a

vs if I don't want it:

first: int list -> int

@RandomDamage @fool
(I forgot `val` before each line, shows that it was a long time since I last used OCaml)

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!