Skip to content

occurs check should not apply to type families

This code:

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

gives this error:

test.hs:5:14:
    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.

Trac metadata
Trac field Value
Version 7.4.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information