# Verifying type families for termination and correctness

**URL:** <https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365>\
**Category:** Learn\
**Created:** [July 8, 2026, 7:57am UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365 "2026-07-08T07:57:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyaitskov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dyaitskov/32/5142_2.png) [@dyaitskov](https://discourse.haskell.org/u/dyaitskov)\
**Post date:** [July 8, 2026, 7:57am UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/1 "2026-07-08T07:57:16Z")

</div>

Hi,

Powerful Haskell type system helps to catch errors, but as the number of type functions and their sizes grows I anticipate the opposite effect and I would like to have a way to verify them.

Is there a tool or technique capable of checking that type family terminates under certain condition? LiquidHaskell and extraction from Agda are the first things that pop up in my head, but they can’t do that, do they?

---

<div class="post-metadata">

**Author:** ![facundominguez](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/facundominguez/32/3486_2.png) [@facundominguez](https://discourse.haskell.org/u/facundominguez)\
**Post date:** [July 8, 2026, 12:48pm UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/2 "2026-07-08T12:48:56Z")

</div>

Hello! I don’t think LiquidHaskell can check termination of type families. If you wanted to do the termination checks with SMT solvers, then changing LiquidHaskell could be worth considering, or using liquid-fixpoint.

I don’t know about Agda. I guess that any translation from and to dependently typed languages could play similar roles.

Other alternatives would be to implement termination checks in a plugin, or in GHC, or in a standalone tool. 🤔

Picking approaches would require collecting and classifying examples of type families that need to be supported.

---

<div class="post-metadata">

**Author:** ![olf](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/olf/32/3813_2.png) [@olf](https://discourse.haskell.org/u/olf)\
**Post date:** [July 8, 2026, 9:33pm UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/3 "2026-07-08T21:33:50Z")

</div>

Interesting question! I’m having difficulties to define what _termination_ even means for type families. Let’s try to work out what is needed to solve this.  
Please correct me if you think any of the following is not accurate.

In first approximation, a type family is a function `f :: Type -> ... -> Type`. Let us forget that we are actually dealing with types and abstract to `f :: t -> ... -> t`.

Next question is, what primitives are available to build `f`?

- We certainly have recursion, otherwise the question of termination would be trivial. But it is not a full untyped or simply-typed lambda calculus, because there is no currying or partial application in type families, right? At least GHC currently does not support this.
- There is no type of type families. In other words, no higher-rank families. `data FamilyKind = Kind | Kind :->: FamilyKind` Note: No `FamilyKind` on the LHS of the arrow.
- We have a context of known type names in scope, which we can regard as elements of `t`. Moreover, type family declarations can be mutually recursive.
- We have pattern matching on values of `t`, at least to some extent. We can certainly match on known primitive types names like `Int`.
- Type families are partial in general. Would you consider a properly partial type family as terminating?

So we have something like a simply-typed lambda calculus, with recursion, (partial) pattern matching and variables, but only application, no lambda abstraction. The [Dec](https://hackage-content.haskell.org/package/template-haskell/docs/Language-Haskell-TH-Syntax.html#t:Dec) type in Template Haskell might give hints where I have over-simplified.

Finally, in our hypothetical universe of type families `t -> ... -> t`, what counts as _termination_? I suppose we need a reduction relation similarly to what we have in lambda calculus and say a type family terminates when variable-free terms have a normal form.

All in all, when you ask for type family termination tools, you should look for tools that can prove normalization in lambda calculi. I don’t know whether the absence of lambda abstraction makes this problem any easier.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [July 8, 2026, 10:06pm UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/4 "2026-07-08T22:06:05Z")

</div>

A naive termination checker like Liquid Haskell has seems relatively straightforward: check if at least one argument (uniformly) shrinks every recursive call (can be extended to cover more cases). There are at least two complications: `Type :: Type` and data types that are not strictly positive. Perhaps those are also not that hard to approximate?

---

<div class="post-metadata">

**Author:** ![GunpowderGuy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/gunpowderguy/32/4164_2.png) [@GunpowderGuy](https://discourse.haskell.org/u/GunpowderGuy)\
**Post date:** [July 14, 2026, 3:00am UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/5 "2026-07-14T03:00:28Z")

</div>

Dependent haskell is being worked on. After this , i think it would be very interesting to see whether termination checking for runtime and type level code ( type families ) , could performed. This would make haskell more in line with idris2, which has dependent types ( but not yet soundness, girards paradox and other problems are still at large, but devs say this could be fixed without upending the language )

---

<div class="post-metadata">

**Author:** ![Ambrose](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/ambrose/32/5672_2.png) [@Ambrose](https://discourse.haskell.org/u/Ambrose)\
**Post date:** [July 14, 2026, 4:25am UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/6 "2026-07-14T04:25:45Z")

</div>

is termination checking on the DH roadmap?

---

<div class="post-metadata">

**Author:** ![int-index](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/int-index/32/4156_2.png) [@int-index](https://discourse.haskell.org/u/int-index)\
**Post date:** [July 14, 2026, 6:26am UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/7 "2026-07-14T06:26:56Z")

</div>

Termination checking falls outside the scope of DH, but it’d be a great post-DH addition.

---

<div class="post-metadata">

**Author:** ![GunpowderGuy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/gunpowderguy/32/4164_2.png) [@GunpowderGuy](https://discourse.haskell.org/u/GunpowderGuy)\
**Post date:** [July 14, 2026, 4:09pm UTC](https://discourse.haskell.org/t/verifying-type-families-for-termination-and-correctness/14365/8 "2026-07-14T16:09:20Z")

</div>

Idris 2, Agda, and other languages with totality checking let you write total functions that:

- Start from finite structures (data), then iterate over them in a way that guarantees that each recursive step reduces the size of the structure. Because the structure gets smaller on every step, the computation is guaranteed to eventually consume it completely and terminate.

- Start from infinite structures (codata). Functions that iterate over them are more constrained. For example, you can build an infinite list (using “list” in the mathematical sense, not necessarily the `List` data structure) of numbers called `real_numbers`. You can then perform operations on it, such as doubling every element or filtering it. However, somewhere along the line, your program must make the result finite. For example, you could double every element and then take a finite number of them.

Data can be computed eagerly (whether it is used or not) or on demand. With totality checking, both evaluation strategies have the same behavior, although their performance can still differ. Eager evaluation is what CPUs are generally designed for and is often easier to optimize, while on-demand evaluation may avoid computing data that is never used.

Without totality checking, a program may enter an infinite loop while computing some data. If that data is never used later, only eager evaluation would enter the loop. With totality checking, this difference disappears because all functions are guaranteed to terminate.

Codata must be computed on demand. Otherwise, an eager evaluation strategy could attempt to evaluate an infinite amount of data before producing any result, so the computation would never finish. With on-demand evaluation, only the portion of the structure that is actually needed is computed.

In the aforementioned languages, ordinary functions and type-level functions are the same. I understand that Dependent Haskell will preserve type families while making them more general. If so, the above should still apply.

Given the above, I wonder:

- Can totality checking be added to GHC after dependent types?
- If so, can it be added in such a way that existing code can be made total without requiring extensive rewrites? It is possible that large parts of a given program would need to be rewritten to make it compatible with totality checking.
- Could totality checking be implemented as a GHC plugin? It may be possible to implement totality checking as an additional set of rules checked by a GHC plugin.

Likewise, could other features needed to make Dependent Haskell sound also be implemented later in GHC or as extensions?

One obvious example is Girard’s paradox. There are several ways to deal with it. The following approach:

[https://idris2.readthedocs.io/en/latest/tutorial/miscellany.html#cumulativity](https://idris2.readthedocs.io/en/latest/tutorial/miscellany.html#cumulativity)

results in code that is almost identical whether cumulativity is present or not. Idris 1 had cumulativity, while Idris 2 does not. As I understand it, existing code should mostly continue to work once the feature is reintroduced, with only extreme edge cases being affected.

Since this does not affect programmers directly and only adds additional rules for the compiler to check, perhaps it could also be implemented as a GHC plugin.

There would still be many other sources of unsoundness not mentioned that would also need to be addressed.  
I hope people can give their 2 cents over the ideas i mentioned. This is a topic that interests me a lot but i am not an expert
