#3701: allow existential wrapper newtypes
------------------------------+---------------------------------------------
Reporter: duncan | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.10.4
Resolution: | Keywords:
Difficulty: | Os: Unknown/Multiple
Testcase: | Architecture: Unknown/Multiple
Failure: None/Unknown |
------------------------------+---------------------------------------------
Comment (by simonpj):
Yes, something like this would be good. Here's a very relevant paper that
Kim Bruce wrote for ECOOP'97: http://www.ifs.uni-
linz.ac.at/~ecoop/cd/papers/1241/12410104.pdf. Just as you propose a type
and a class with the same name, so does he, but he calls them T and #T.
But it's not that easy to just "derive the instance". In your case:
{{{
data MkCompiler where
MkCompiler :: Compiler c => c -> MkCompiler
instance Compiler MkCompiler where
getInstalledPackages (MkCompiler c) = getInstalledPackages c
}}}
Notice that this instance of `getInstalledPackages` is necessarily strict.
And I think it ''requires'' a OO-style type for `getInstalledPackages`:
that is, the first argument has type 'c'. So classes that are amenable
are of form
{{{
class C a b c where
op1 :: c -> <blah>
op2 :: c -> <blah>
etc
}}}
For classes of that form, we could regard `(C t1 t2)` as a data type, with
a single existential constructor, declared (implicitly) thus
{{{
data C a b where
C :: forall a b c. C a b c => c -> C a b
instance C (C a b) where
op1 (C x) = op1 x
op2 (C x) = op2 x
}}}
It's a little uncomfortable that this stuff only works when the class has
the right shaped signature.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3701#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs