[GHC] #3197: disambiguating type family instances with qualified
names not possible
GHC
trac at galois.com
Tue Apr 28 12:38:29 EDT 2009
#3197: disambiguating type family instances with qualified names not possible
-----------------------------+----------------------------------------------
Reporter: claus | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler (Type checker)
Version: 6.11 | Severity: normal
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
-----------------------------+----------------------------------------------
While reading [http://www.haskell.org/pipermail/haskell-
cafe/2009-April/060665.html 1], it occured to me that type families could
be used to parameterize modules by types. So I modified my example from
[http://www.haskell.org/pipermail/haskell-cafe/2009-April/060324.html 2],
trying to parameterize two modules `A` and `B` with a shared type `Label`
(sharing expressed in `C)`, but ran into a few issues:
{{{
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE EmptyDataDecls #-}
module LA where
data MyLabel
y = undefined::MyLabel
type family Label a
z = undefined::Label ()
}}}
{{{
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE EmptyDataDecls #-}
module LB where
data MyLabel
y = undefined::MyLabel
type family Label a
z = undefined::Label ()
}}}
{{{
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeFamilies #-}
module LC where
import LA
import LB
-- fails = [LA.y,LB.y]
-- express type sharing while leaving actual type open
type family Label a
type instance LA.Label a = LC.Label a
type instance LB.Label a = LC.Label a
ok2 = [LA.z,LB.z]
-- for testing only
-- type instance Label a = () -- can't use with or without qualifier:-(
}}}
Issues:
- is it really necessary for type families to have at least one index?
Without that, type constants could be expressed directly
- uncommenting that last line demonstrates a couple of bugs:
* as it stands, the type instance is ambiguous, but the error message
has an incorrect source location (`1:0`)
* trying to disambiguate by defining `type instance LC.Label` results
in : "Qualified name in binding position: LC.Label" (note that this is
permitted a couple of lines up, so it is related to whether the qualifier
refers to the current module or an imported one)
[the bug is not really in the type checker, but specific to type
families..]
Bug aside, it works (`length ok2` gives two, not an error, as `fail`
would).
This could be a useful type family programming pattern (it is probably
implicit in the comparisons of SML functors vs Haskell type
classes/families, I just don't recall it being made so explicit before,
just focussing on type parameterization and sharing)!-)
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3197>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list