Session

Playing with types: An experimental structural type system for Kotlin

Kotlin's powerful static type system is based on nominal typing – let's explore how we might implement structural typing by leveraging Kotlin and the Gradle build system.

When comparing type systems in different languages, one of the fundamental distinctions is between nominal and structural typing.
- In nominal typing, types are considered equal when they have the same (qualified) name – Kotlin's type system is based on nominal typing.
- In structural typing, types are considered equal when they have the same structure – TypeScript is a prominent example of structural typing.
It is worth noting that some statically typed languages, like Elm, support both.

Structural typing provides some extra flexibility, as types can be deemed compatible without explicitly implementing a common interface. That way, types of the same shape defined in different, unrelated codebases can be compatible without introducing a dependency. Also, functionality that depends on the shape of a type may accept any type matching that shape, facilitating code reuse.

In this talk, we'll explore an implementation of structural typing in Kotlin – as an experiment, based on existing language features.

We'll start by considering the differences between nominal and structural typing, their pros and cons and some use cases. Then we'll look at some type theory, specifically algebraic data types (ADTs) and how they are implemented through nominal/structural typing respectively. We'll also look at how this relates to Kotlin's `typealias` feature and the implications for type safety. Finally, I will take you through an implementation of structural typing, leveraging features of the Kotlin programming language and the Gradle build system.

Merlin Pahic

Staff Software Engineer at EIDU, a social enterprise dedicated to improving learning outcomes for children in low-resource settings worldwide.

Berlin, Germany

Actions

Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.

Jump to top