3 ms·
Two thoughts: For this problem, I would use union types in Julia. Union types are a sort of sum, but they are amalgamated sums whilst sums types in PL semantic
by chalst 6y ago
Two thoughts:
For this problem, I would use union types in Julia. Union types are a sort of sum, but they are amalgamated sums whilst sums types in PL semantics usually means disjoint sums. The difference is that disjoint sums 'mark' whether a value is of the left or right type, while with amalgamated sums the value may belong unmarked to the intersection. The distinction does not matter in the example the post gives.
Second, Julia does not give the benefit that Rust gives of type coverage, that is, ensuring that functions that take the sum type as argument actually are defined for each branch of the sum type. The Rust compiler guarantees this automatically. AFAICS, with Julia it is up to the user to provide tests exploring the branches.
- bocckoka 6y agoJulia is a dynamic language, I don't think having the rigor of a compiled language (probably the most rigorous out there) is a reasonable expectation. It would be nice to have as an external linter service, probably.
- pa7x1 6y agoI think you are mixing two different things. Julia is a compiled language and Rust is too. Julia is dynamically typed while Rust is statically typed.
- chalst 6y agoIt is possible to check type coverage for dynamically typed languages, if the compiler/interpreter has enough type information to infer what types need coverage. In the case of multimethods, Julia's compiler is given this information.