Ticket #3346 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

Strange and incorrect type error when using rewrite rules with type families

Reported by: dreixel Owned by:
Priority: normal Milestone: 6.12.1
Component: Compiler Version: 6.11
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: typecheck/should_compile/T3346 Blocked By:
Blocking: Related Tickets:

Description

The following code

{-# OPTIONS_GHC -fglasgow-exts -O1 #-}

module Main where

{-# RULES "rule1"   forall x. to (from x) = x #-}
{-# RULES "rule2"   forall x. from (to x) = x #-}

class EP a where
  type Result a
  from :: a -> Result a
  to   :: Result a -> a

gives the compilation error with GHC 6.11.20090703:

    Couldn't match expected type `Result a'
           against inferred type `Result a'
      NB: `Result' is a type function, and may not be injective
    In the first argument of `to', namely `(from x)'
    In the expression: to (from x)
    When checking the transformation rule "rule1"

I don't understand this error. rule2 seems unproblematic, though.

The similar code with functional dependencies

{-# RULES "rule3"   forall x. to' (from' x) = x #-}
{-# RULES "rule4"   forall x. from' (to' x) = x #-}

class EP' a b | a -> b where
  from' :: a -> b
  to'   :: b -> a

raises no errors.

Attachments

Main.hs Download (0.8 KB) - added by dreixel 3 years ago.

Change History

Changed 3 years ago by dreixel

Changed 3 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.12.1

Changed 3 years ago by simonpj

  • status changed from new to closed
  • testcase set to typecheck/should_compile/T3346
  • resolution set to fixed

You are right, that is bogus. Fixed by

Fri Jul 17 16:57:22 BST 2009  simonpj@microsoft.com
  * Fix Trac #3346: tcSimplify for LHS of RULES with type equalities

    M ./compiler/typecheck/TcSimplify.lhs -2 +12

There was special handling for constraints on the LHS of a RULE, which hadn't been updated to account for type families.

Thanks for the report. I've added a regression test

Simon

Note: See TracTickets for help on using tickets.