patch applied (ghc): Improve handling of newtypes (fixes Trac 1495)
Simon Peyton Jones
simonpj at microsoft.com
Fri Dec 21 04:18:25 EST 2007
Fri Dec 21 01:04:06 PST 2007 simonpj at microsoft.com
* Improve handling of newtypes (fixes Trac 1495)
In a few places we want to "look through" newtypes to get to the
representation type. But we need to be careful that we don't fall
into an ininite loop with e.g.
newtype T = MkT T
The old mechansim for doing this was to have a field nt_rep, inside
a newtype TyCon, that gave the "ultimate representation" of the type.
But that failed for Trac 1495, which looked like this:
newtype Fix a = Fix (a (Fix a))
data I a = I a
Then, expanding the type (Fix I) went on for ever.
The right thing to do seems to be to check for loops when epxanding
the *type*, rather than in the *tycon*. This patch does that,
- Removes nt_rep from TyCon
- Make Type.repType check for loops
See Note [Expanding newtypes] in Type.lhs.
At the same time I also fixed a bug for Roman, where newtypes were not
being expanded properly in FamInstEnv.topNormaliseType. This function
and Type.repType share a common structure.
Ian, see if this merges easily to the branch
If not, I don't think it's essential to fix 6.8
M ./compiler/coreSyn/MkExternalCore.lhs -4 +2
M ./compiler/iface/BuildTyCl.lhs -38 +1
M ./compiler/main/TidyPgm.lhs -2 +3
M ./compiler/typecheck/TcDeriv.lhs -4 +4
M ./compiler/types/FamInstEnv.lhs -37 +68
M ./compiler/types/TyCon.lhs -24 +3
M ./compiler/types/Type.lhs -12 +46
More information about the Cvs-ghc