Question

Just having a hard time understanding if Visual Basic uses structure or name type equivalence (or both).

Was it helpful?

Solution

Visual Basic is nominatively ("by name") typed - and not structurally typed.

While VB.NET supports "late dispatch" or dynamic typing via "Strict Off", this is not related to the underlying (CLR) type system. In addition, "Infer On" is also an orthogonal construct as the compiler still figures out the types "by name".

Basically: if a type name is required to achieve static typing (e.g. for "type equivalency"), then it is a nominatively typed language.


Even languages like Ruby/Python are nominatively typed. However, because they are also entirely dynamically typed and explicit type-checking is often eschewed, it is often considered that the types therein are "used structurally". That is, if it quacks like a duck..

An example of a language with structural typing support is Scala. Consider this small example where A and B are independent types (they do not share an interface or relevant super type) but they can be unified around their structure (aliased as T):

case class A { def hi = "A" }
case class B { def hi = "B" }

// structure declaration: aliased, but "nameless"
type T = { def hi: String }  
// both A and B can be "used as" the structure declared
def sayHi (it: T) = println(it.hi)

sayHi(A())
sayHi(B())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top