Skip to content

"equirecursive" type family leads to stack overflow in ghci

Summary

Trying to typecheck a term using a (silly) type family such that T ~ Maybe T leads to a stack overflow (instead of a proper type error from reaching the max reduction depth, if this is to be an error at all).

Steps to reproduce

> :set -XTypeFamilies -XUndecidableInstances
> type family T where T = Maybe T
> :t Nothing @T
Nothing @T*** Exception: stack overflow

(where the exception takes a few seconds to appear)

Compare that output to this variant that immediately produces a proper type error:

> :t Nothing @T :: T

<interactive>:5:1 error:
...

Expected behavior

Either a success (Nothing @T has type Maybe T without requiring any type conversion), or a type error instead of an internal exception.

Environment

  • GHC version used: 8.10.1
Edited by Xia Li-yao
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information