4 ms·
> I advise you to update your language knowledge to Java 24, C# 13, Scala 3. I'll update it when I need it :P I'm pretty sure I'll never need Scala 3. > Into
by Ygg2 1y ago
> I advise you to update your language knowledge to Java 24, C# 13, Scala 3.
I'll update it when I need it :P I'm pretty sure I'll never need Scala 3.
> Into the Java ADTs that you say Java doesn't have for sure
That still seems like casting to a common object + a bunch of instanceof. But I guess if it looks like a duck and walks like a duck.
> C #13
Wait. You mentioned C# has ADTs via sealed classes IIUC. Why the hell do they have a https://github.com/dotnet/csharplang/issues/8928 https://github.com/dotnet/csharplang/issues/8928 ticket for discriminated unions then?
It implies that there are some differences between sealed interfaces and discriminated unions. Perhaps how they handle value types (structs and ref structs).
- pjmlp 1y agoIn no such way I mentioned C# has ADTs, > Java and Scala certainly have ADTs, while Scala and C# have nullable types support.
- Ygg2 1y agoThen why did you tell me to update my knowledge of C#? It wasn't wrong for the discussion at hand. Also, you failed to mention that the generics ADT in Java is still abysmal (it's relevant, because the topic started as boosting productivity in Java with ADT, I don't find ClassCastException as really boosting anything outside my blood pressure): sealed interface Result<T, E> permits Ok, Error { } record Error<E>(E error) implements Result<Object, E> {} record Ok<T>(T value) implements Result<T, Object> {} //public <T, E> Object eval(Result<T, E> exp) { // return switch (exp) { // case Error<E> error -> error.error; // case Ok<T> ok -> ok.value; // }; //} public <T, E> Object eval(Result<T, E> exp) { return switch (exp) { case Error error -> (E) error.error; case Ok ok -> (T) ok.value; }; } Guess I'll wait for Java 133 to get reified generics.
- pjmlp 1y agoBecause your English reading comprehension missed the fact I was talking about the nullability improvements. Given the expert level, you are certainly aware that most ML languages don't have reified polymorphism on their implementations, right?
- Ygg2 1y ago> Because your English reading comprehension missed the fact I was talking about the nullability improvements. Tank you :P Never claimed to be native English speaker. Were there any meaningful changes in nullability semantics between C# 8.0 and C# 14.0? The issue I encountered was related to a complex game engine doing some runtime reflection, dependency injection, code gen and so forth. I also never claimed to be ML expert. But them being reified or not, doesn't change my point that ADT in Java much like generics look like a design afterthought.
- lock1 1y agoYeah, Java's generics still kind of suck. There's a rumor after project Valhalla, Java language maintainers might add reified generics in the future. However, I think the current state of Java ADT & generic isn't that bad for most purposes. Though due to its nullable-by-default type system and backward compatibility, there's a decent amount of footguns if you're trying to mix Java's FP & ADT with code that utilizes nulls. About your code example, you could just do something like this to avoid explicit casting sealed interface Result<T,E> { record Ok<T,E>(T value) implements Result<T,E> {} record Error<T,E>(E error) implements Result<T,E> {} public static <T,E> Object eval(Result<T,E> res) { if (res instanceof Error<T,E>(E e)) // Rust's if let System.out.println(e); return switch (res) { case Ok(T v) -> v; case Error(E e) -> e; }; } } The new "pattern matching" feature of `instanceof` is certainly handy to avoid stupid ClassCastException.