[GHC] #8161: Associated type parameters that are more specific than the instance header
GHC
ghc-devs at haskell.org
Fri Aug 23 12:46:00 UTC 2013
#8161: Associated type parameters that are more specific than the instance header
-------------------------------------+-------------------------------------
Reporter: adamgundry | Owner:
Type: feature request | Status: new
Priority: low | Milestone:
Component: Compiler (Type | Version: 7.7
checker) | Operating System: Unknown/Multiple
Keywords: | Type of failure: GHC rejects
Architecture: Unknown/Multiple | valid program
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
-------------------------------------+-------------------------------------
It would be nice if type parameters of associated types could be more
specific than those in the instance header. This is currently rejected
with the message "Type indexes must match class instance head", but could
be accepted:
{{{
{-# LANGUAGE TypeFamilies #-}
class C a where
type T a
instance C [a] where
type T [Bool] = Int
type T [Int] = Int
}}}
More typically, this is useful where we want to use an equality constraint
to make type inference easier, but need to match on the actual type in an
associated type:
{{{
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
class C a where
type T a
instance a ~ [b] => C a where
type T [b] = Int
}}}
This showed up in the implementation of
[wiki:Records/OverloadedRecordFields/Plan OverloadedRecordFields]. Of
course, one can always work around it using a normal (non-associated) type
family.
Note that we already allow type families to specialise variables that do
not occur in the instance header:
{{{
{-# LANGUAGE TypeFamilies #-}
class C a where
type T a b
instance C [a] where
type T [a] [Bool] = Bool
type T [a] [Int] = Int
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8161>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list