F-Bounded Polymorphism: Recursive Type Signatures in Scala

Back to Blog Home

Have you seen a type signature like this before?

trait T[U <: T[U]]

F-bounded polymorphism (a.k.a self-referential types, recursive type signatures, recursively bounded quantification) is a powerful object-oriented technique that leverages the type system to encode constraints on generics.

Marconi Lanna explains how to define and use F-bounded types in Scala, enlisting the compiler to enforce advanced trait semantics, while greatly reducing and simplifying unit tests.

Further Resources

Copyright © 2021 ProTech Professional Technical Services, Inc. All Rights Reserved.

Sign In Create Account


Social Media