Scala types map

Scala has a strong static type system which arguably can be considered complex.

For my own benefit, this is an attempt at mapping Scala's 2.11.7 type hierarchy interactively.

Unlike Java where you have primitive types which step out of the hierarchy, Scala has a unified type system where all types descend from Any (a "top type", ⊤, in type theory), which in the standard library has two direct subtypes (AnyRef and AnyVal). At the other end of type hierarchy1 (commonly called the "bottom types", ⊥) we have Null$ and Nothing$. In essence all of Scala's remaining library types will live between ⊤ and ⊥. The nodes in the graph are coloured according to its category, i.e. class, trait, object or case class, aliases in the standard library are kept with their nominal value and there is no distinction between class and abstract class.

When a type is selected, the tree paths will represent all the upwards reachable nodes, this is, its immediate successors (and successors' successors) will be highlighted up the hierarchy.

You can select types using the URL. To pre-select a type and it's ascendants go to, for instance:

If you have any suggestions or comments, please leave them at @ruimvieira on Twitter.

A map of Scala types

1 - One of the existential reasons for ⊥ is closely related to the Turing Halting Problem and how to fit it within a consistent strong static type system.

Without going into too much detail (perhaps a future blog post), these types exist partly to represent the result of computations for which the Scala compiler can't easily deduce the result type. Let's assume we have a never ending computation represented by the function foo:

def foo():T = ???
What should T be? While in many other languages (notoriously, Java) we could get away with typing foo with just about anything (for instance, String or TransactionAwarePersistenceManagerFactoryProxy), Scala is more strict, since we can't verify that assertion. The solution within our type system is simply to declare
def foo():Nothing = ???
Of course that in Java you could write void interpreted as "return nothing". However, to a functional programmer, having a function that returns nothing (which is quite different from Unit) is surely a code smell.