E-Ink News Daily

Back to list

Dependent if expressions without dependent types

The article demonstrates a folklore Haskell trick to implement dependent if expressions—branches returning different types—without requiring actual dependent types. Using the RebindableSyntax extension and Church-encoded booleans, the technique redefines if-then-else to infer return types from branch contexts, working in any Hindley-Milner typed language.

Background

Dependent types allow values to influence types, enabling more precise type-level guarantees. This article explores how similar expressiveness can be approximated in languages with simpler type systems like Haskell using type inference tricks.

Source
Lobsters
Published
Sep 3, 2026 at 01:52 AM
Score
5.0 / 10