Opened 3 months ago

Closed 3 months ago

#8651 closed bug (fixed)

'Untouchable' error when using type function in class constraint in rank-2 type

Reported by: sbarclay Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: indexed_types/should_compile/T8651 Blocked By:
Blocking: Related Tickets: #8644 #7594


I noticed there are some cases that no longer compile after the recent fix for #8644, such as the following:

{-# LANGUAGE RankNTypes, FlexibleContexts, TypeFamilies #-}

import Data.Monoid

type family Id a

type instance Id a = a
--type instance Id [a] = [Id a]

foo :: (Monoid (Id String) => r) -> r
foo x = x

main :: IO ()
main = print $ foo "Hello"

Attempting to compile this on HEAD produces the same error in 'main' as reported in the earlier ticket:

    Couldn't match expected type ‛s0’ with actual type ‛[Char]’
      ‛s0’ is untouchable

However, it compiles fine if the commented-out type family instance is used instead. It also compiles fine if the type family is replaced with an ordinary type synonym:

type Id a = a

I guess that the problem is caused by equalities of the form t ~ [Char] introduced by the type family instance.

Change History (3)

comment:1 Changed 3 months ago by Simon Peyton Jones <simonpj@…>

In 5d2fb2ee94fea4cf62ba767eb1555e42f4f21f46/ghc:

Further refine the test for 'given' equalities

Trac #8651 revealed that my previous fix (itself in response to #8644)
wasn't quite right.  The plan, using the CtOrigin to identify
constraints arising from flattening, is described in TcSimplify,
Note [When does an implication have given equalities?]

comment:2 Changed 3 months ago by Simon Peyton Jones <simonpj@…>

comment:3 Changed 3 months ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to indexed_types/should_compile/T8651

Very excellent catch, thank you.


Note: See TracTickets for help on using tickets.