Opened 3 years ago

Closed 3 years ago

#5377 closed bug (invalid)

TypeSynonymInstances dysfunctional in ghc-7.2.1-rc1?

Reported by: hvr Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.1
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: GHC rejects valid program Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The following code causes GHC to suggest enabling the TypeSynonymInstances? language extension:

type Foo = Maybe Int

class Bar x where
  bar :: x -> ()
  bar _ = ()

instance Bar Int

instance Bar Foo

but adding a {-# LANGUAGE TypeSynonymInstances #-} doesn't suffice, as GHC then suggests enabling FlexibleInstances? instead.

With ghc-7.0.4 the TypeSynonymInstances? extension by itself was enough to make the code above compile. This breaks compilation for a few packages on hackage which assume that TypeSynonymInstances? suffices.

Change History (6)

comment:1 Changed 3 years ago by hvr

For completeness:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.2.0.20110728

$ ghc -c ghc_ticket_5377.hs 

ghc_ticket_5377.hs:9:10:
    Illegal instance declaration for `Bar Foo'
      (All instance types must be of the form (T t1 ... tn)
       where T is not a synonym.
       Use -XTypeSynonymInstances if you want to disable this.)
    In the instance declaration for `Bar Foo'

$ ghc -XTypeSynonymInstances  -c ghc_ticket_5377.hs 

ghc_ticket_5377.hs:9:10:
    Illegal instance declaration for `Bar Foo'
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use -XFlexibleInstances if you want to disable this.)
    In the instance declaration for `Bar Foo'

$ ghc -XFlexibleInstances  -c ghc_ticket_5377.hs 

ghc_ticket_5377.hs:1:1:
    The function `main' is not defined in module `Main'

comment:2 Changed 3 years ago by simonpj

Hmm. I made this change to fix #4841!

I can see several alternatives

  • Make no further change
  • Reverse the change in #4841.
  • Make TypeSynonymInstances imply FlexibleInstances. Since #4841 made the latter imply the former, that would make them equivalent. So abolish TypeSynonymInstances altogether (leaving it in but deprecated for one release round).

I don't feel strongly. The last option looks best to me because it's a simplification and I don't think it's important to distinguish the two extensions.

Simon

comment:3 Changed 3 years ago by hvr

Oh... I didn't realize that TypeSynonymInstances was actually misbehaving before ghc-7.2 as I didn't fully comprehend that TypeSynonymInstances was really only meant to accomplish simple type-synonym RHS substitution and nothing beyond that... :-/

Sorry for the noise

comment:4 Changed 3 years ago by igloo

The first option seems fine to me. I think it's simpler as a user to understand the two separate extensions than one combined extension.

Other advantages of keeping the two extensions separate: other implementations can implement one but not the other; Haskell' can standardise one but not the other.

comment:5 Changed 3 years ago by hvr

btw, is this a noteworthy item for the GHC 7.2.1 release notes?

comment:6 Changed 3 years ago by simonpj

  • Resolution set to invalid
  • Status changed from new to closed

OK, lets leave it as it is. Maybe a mention in the release notes

Note: See TracTickets for help on using tickets.