[Haskell-cafe] Re: Non-termination of type-checking

oleg at okmij.org oleg at okmij.org
Fri Jan 29 02:56:31 EST 2010

Here is a bit more simplified version of the example. The example has
no value level recursion and no overt recursive types, and no impredicative
polymorphism. The key is the observation, made earlier, that two types
	c (c ()) and R (c ())
unify when c = R. Although the GADTs R c below is not recursive, when
we instantiate c = R, it becomes recursive, with the negative
occurrence. The trouble is imminent.

We reach the conclusion that an instance of a non-recursive GADT 
can be a recursive type. GADT may harbor recursion, so to speak.

The code below, when loaded into GHCi 6.10.4, diverges on
type-checking. It type-checks when we comment-out absurd.

{-# LANGUAGE GADTs, EmptyDataDecls #-}

data False				-- No constructors

data R c where				-- Not recursive
    R :: (c (c ()) -> False) -> R (c ())

-- instantiate c to R, so (c (c ())) and R (c ()) coincide
-- and we obtain a recursive type
--    mu R. (R (R ()) -> False) -> R (R ())

cond_false :: R (R ()) -> False
cond_false x@(R f) = f x

absurd :: False
absurd = cond_false (R cond_false)

More information about the Haskell-Cafe mailing list