- n_subtermsP= length subTtypesP
- subTermTvs <- mapM (liftM mkTyVarTy . newVar ) (map typeKind subTtypesP)
- baseType <- instScheme (dataConRepType dc)
- let myType = mkFunTys (reOrderTerms subTermTvs subTtypesNP subTtypes) tv
- addConstraint myType baseType
- subTermsP <- sequence [ extractSubterm i tv (ptrs clos)
- | (i,tv) <- zip [extra_args..extra_args + n_subtermsP - 1]
- subTermTvs ]
+ subTermTvs <- sequence
+ [ if isMonomorphic t then return t else (mkTyVarTy `fmap` newVar k)
+ | (t,k) <- zip subTtypesP (map typeKind subTtypesP)]
+ -- It is vital for newtype reconstruction that the unification step is done
+ -- right here, _before_ the subterms are RTTI reconstructed.
+ when (not monomorphic) $ do
+ let myType = mkFunTys (reOrderTerms subTermTvs subTtypesNP subTtypes) tv
+ instScheme(dataConRepType dc) >>= addConstraint myType
+ subTermsP <- sequence $ drop extra_args -- all extra arguments are pointed
+ [ appArr (go tv t) (ptrs clos) i
+ | (i,tv,t) <- zip3 [0..] subTermTvs subTtypesP]