Opened 5 years ago

Closed 5 years ago

#6123 closed bug (fixed)

occurs check should not apply to type families

Reported by: dmwit Owned by: simonpj
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: indexed-types/should_fail/T6123
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This code:

{-# LANGUAGE TypeFamilies #-}
type family Id a
cid :: a ~ Id a => a -> a
cid x = x
cundefined = cid undefined

gives this error:

    Occurs check: cannot construct the infinite type: a0 = Id a0
    In the expression: cid undefined
    In an equation for `cundefined': cundefined = cid undefined

whereas I think it should be possible to infer the type cundefined :: a ~ Id a => a. Equations with a variable on one side and a type family at the head of the other side should become constraints rather than being subject to the occurs check.

Change History (3)

comment:1 Changed 5 years ago by simonpj

difficulty: Unknown
Owner: set to simonpj

comment:2 Changed 5 years ago by simonpj@…

commit 05289c2ac1203a5d5bbe8236d0239946b5093116

Author: Simon Peyton Jones <>
Date:   Fri May 25 11:45:53 2012 +0100

    Improve occurs-check error reporting (fix Trac #6123)
    We were wrongly reporting (a ~ F a) as an occurs-check error
    when F is a type function.

 compiler/typecheck/TcCanonical.lhs |  112 ++++++++++++++++++-----------------
 compiler/typecheck/TcErrors.lhs    |   41 ++++++--------
 compiler/typecheck/TcInteract.lhs  |    5 ++
 3 files changed, 80 insertions(+), 78 deletions(-)

comment:3 Changed 5 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: indexed-types/should_fail/T6123
Note: See TracTickets for help on using tickets.