4 ms·
Here's a counter example. I've seen numerous Java projects define a nominal predicate type, for example com.google.common.base.Predicate. None of these are inte
by grumpyprole 5y ago
Here's a counter example. I've seen numerous Java projects define a nominal predicate type, for example com.google.common.base.Predicate. None of these are interoperable without writing adapter code. ML and Haskell would essentially use a structural type:
t -> bool
Much simpler and easier to consume.
How would you assign a nominal type to the result of a SQL query?
So there are arguments on both sides. My point was that structural types can always easily be turned into a nominal type, but not the other way around. Therefore they should be the default.
- de_keyboard 5y agofunction types are structural in most nominally-typed languages I have used, perhaps a poor example?
- grumpyprole 5y agoAre you sure? What language are you referring to? For example, although Java method definitions are essentially defined in terms of tuples, function classes and objects in Java are all entirely nominal.
- _old_dude_ 5y agoThere are interoperable since Java 8, using the operator :: com.google.common.base.Predicate<String> guavaPredicate = ... java.util.function.Predicate<String> predicate = guavaPredicate::apply;
- Twisol 5y agoThe :: syntax minimizes the pain, but the fact you have to do it at all is still irritating, and IIUC it incurs a small runtime cost due to the intermediate object that's generated to convert between the two interfaces. I recently cleared out some of these intermediaries in a hot area of code and got a small but significant performance boost.