News for hackers. Stuff that matters.
Re:Dada, an Experiement by the Creators of Rust by BoppreH on Wednesday March 06, 2024 @08:01AM (#39615488)
I've always wondered if global type inference wouldn't be a game changer. Maybe it could be fast enough with caching and careful language semantics?

You could still have your IDE showing you type hints as documentation, but have inferred types to be more fine grained than humans have patience for. Track units, container emptiness, numeric ranges, side effects and idempotency, tainted values for security, maybe even estimated complexity.

Then you can tap into this type system to reject bad programs ("can't get max element of potentially empty array") and optimizations (can use brute force algorithm because n is know to be small).

Such a language could cover more of the script-systems spectrum.

Re:Dada, an Experiement by the Creators of Rust by bananapub on Wednesday March 06, 2024 @08:06AM (#39615526)
one of the other reasons global inference isn't used is because it causes weird spooky action at a distance - changing how something is used in one place will break other code.
Re:Dada, an Experiement by the Creators of Rust by BoppreH on Wednesday March 06, 2024 @08:10AM (#39615562)
I've heard that, but never seen an example*. If the type system complains of an issue in other code after a local change, doesn't that mean that the other code indeed needs updating (modulo false positives, which should be rarer with granular types).

Or is this about libraries and API compatibility?

* I have seen examples of spooky-action-at-a-distance where usage of a function changes its inferred type, but that goes away if functions are allowed to have union types, which is complicated but not impossible. See: https://github.com/microsoft/TypeScript/issues/15114

Re:Dada, an Experiement by the Creators of Rust by nu11ptr on Wednesday March 06, 2024 @08:36AM (#39615796)
Try writing a larger OCaml program and not using interface files. It definitely happens.
Re:Dada, an Experiement by the Creators of Rust by BoppreH on Wednesday March 06, 2024 @09:55AM (#39616601)
I've never used OCaml, so I'm curious to what exactly happens, and if language design can prevent that.

If I download a random project and delete the interface files, will that be enough to see issues, or is it something that happens when writing new code?

Re:Dada, an Experiement by the Creators of Rust by nu11ptr on Wednesday March 06, 2024 @10:15AM (#39616820)
If you delete your interface files and then change the type used when calling a function it can cascade through your program and change the type of the function parameter. For this reason, I generally feel function level explicit types are a fair compromise. However, making that convention instead of required (so as to allow fast prototyping) is probably fine.
Re:Dada, an Experiement by the Creators of Rust by iopq on Wednesday March 06, 2024 @04:32PM (#39621812)
Just require it for public functions. Your own code can be as messy as you want unser the hood
Re:Dada, an Experiement by the Creators of Rust by Narishma on Wednesday March 06, 2024 @10:26AM (#39616940)
> If the type system complains of an issue in other code after a local change, doesn't that mean that the other code indeed needs updating

The problem is when it doesn't complain but instead infers some different type that happens to match.

Re:Dada, an Experiement by the Creators of Rust by mattgreenrocks on Wednesday March 06, 2024 @09:56AM (#39616625)
Type inference is powerful but probably too powerful for module-level (e.g. global) declarations.

Despite type systems being powerful enough to figure out what types should be via unification, I don't think asking programmers to write the types of module declarations is too much. This is one area where forcing work on the programmer is really useful to ensure that they are tracking boundary interface changes correctly.

Re:Dada, an Experiement by the Creators of Rust by BoppreH on Wednesday March 06, 2024 @11:57AM (#39617962)
People accept manually entering types only at a relatively high level. It'd be different if types were "function that takes a non-empty list of even numbers between 2 and 100, and a possibly tainted non-negative non-NaN float in meters/second, returning a length-4 alphanumeric string without side effects in O(n)".
Re:Dada, an Experiement by the Creators of Rust by 63stack on Wednesday March 06, 2024 @02:12PM (#39619930)
I dabbled a bit with ReasonML which has global type inference, and the error messages from the compiler became very confusing. I assume that's a big reason for not gaining more adoption.