logoalt Hacker News

moron4hireyesterday at 4:29 PM4 repliesview on HN

Also called Nominal Typing. I generally consider it a mistake. Interfaces aren't just a bag of fields and methods. They encode semantics, too. Otherwise, you could dismiss employees with a gun or by loading them into a kiln.


Replies

pxeger1yesterday at 5:24 PM

I think you mean structural typing; nominal typing is the opposite, where field names are lexically scoped.

Anyway, row polymorphism can technically be used with nominal typing, it's just that it usually makes sense to use structural typing instead.

The key benefit of row polymorphism is a bit of an implementation detail - it lets you get something resembling (a limited form of) subtyping in your language, without needing as complicated a type inference algorithm as fully-general subtyping requires.

Row polymorphism can be (IMO should usually be) made opt-in, so you can avoid problems like the scenario you describe.

tinesyesterday at 4:45 PM

Nominal typing is the opposite, I think you're thinking of structural typing, no?

show 1 reply
taericyesterday at 4:57 PM

I am not entirely sure I disagree. I think context is often a big factor in semantics, though? The problem with interfaces is often that people think they do all of the work by themselves. But, that is only true within the context of how you use some data. And people tend to accidentally constrain themselves too heavily.

You can make the same argument for numbers, for an easy exploration. Just look at all of the tools that you can have at your disposal by thinking of things as numbers.

michael1999yesterday at 5:05 PM

In the original relational papers, column names were basically types. In a OO world, that doesn't make sense, but in a relational world, it does.