Opened 3 years ago

Closed 3 years ago

#10300 closed bug (invalid)

GHC rejects typeclass with associated type

Reported by: mhwombat Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: 10020 Differential Rev(s):
Wiki Page:

Description

In GHC 7.8.4, the following code is legal:

{-# LANGUAGE TypeFamilies, FlexibleContexts #-}
    
class FiniteGrid g where
  type Size s
  size :: g -> Size g
  maxPossibleDistance :: g -> Int

But with GHC 7.10.1, it no longer compiles. The error message is:

The associated type ‘Size’
mentions none of the type or kind variables of the class ‘FiniteGrid g’
In the class declaration for ‘FiniteGrid’

I didn't see any mention of this in the migration guide, but perhaps there's another pragma I need to enable. I thought this might be related to https://ghc.haskell.org/trac/ghc/ticket/10020, but that bug is apparently fixed in GHC 7.10.1.

Change History (2)

comment:1 Changed 3 years ago by mhwombat

Summary: GHC rejectsGHC rejects typeclass with associated type

comment:2 Changed 3 years ago by simonpj

Resolution: invalid
Status: newclosed

There's nothing to connect Size with FiniteGrid; it's not an associated type at all. You can just define it separately:

type family Size s

class FiniteGrid g where
  size :: g -> Size g
  maxPossibleDistance :: g -> Int

Or, if you want to guarantee you always have an instance of Size g whenever you have an instance of FiniteGrid g, then use g in Size's definition:

class FiniteGrid g where
  type Size g
  size :: g -> Size g
  maxPossibleDistance :: g -> Int

This isn't a bug in 7.10; rather it was a bug in 7.8.

Note: See TracTickets for help on using tickets.