tv <- case (isMonomorphic `fmap` mb_ty) of
Just True -> return (fromJust mb_ty)
_ -> do
- tv <- liftM mkTyVarTy (newVar argTypeKind)
- instScheme (sigmaType$ fromJust mb_ty) >>= addConstraint tv
- return tv
+ tv_ <- liftM mkTyVarTy (newVar argTypeKind)
+ when (isJust mb_ty) $
+ instScheme (sigmaType$ fromJust mb_ty) >>= addConstraint tv_
+ return tv_
go tv (fromMaybe tv mb_ty) hval
where
go tv ty a = do
subTerms = reOrderTerms subTermsP subTermsNP (drop extra_args subTtypes)
return (Term tv dc a subTerms)
-- The otherwise case: can be a Thunk,AP,PAP,etc.
- otherwise -> do
+ otherwise ->
return (Suspension (tipe clos) (Just tv) a Nothing)
-- Access the array of pointers and recurse down. Needs to be done with
-- correct order.
reOrderTerms _ _ [] = []
reOrderTerms pointed unpointed (ty:tys)
- | isPointed ty = head pointed : reOrderTerms (tailSafe "reorderTerms1" pointed) unpointed tys
- | otherwise = head unpointed : reOrderTerms pointed (tailSafe "reorderTerms2" unpointed) tys
-
-tailSafe msg [] = error msg
-tailSafe _ (x:xs) = xs
+ | isPointed ty = ASSERT2(not(null pointed)
+ , ptext SLIT("reOrderTerms") $$ (ppr pointed $$ ppr unpointed))
+ head pointed : reOrderTerms (tail pointed) unpointed tys
+ | otherwise = ASSERT2(not(null unpointed)
+ , ptext SLIT("reOrderTerms") $$ (ppr pointed $$ ppr unpointed))
+ head unpointed : reOrderTerms pointed (tail unpointed) tys
isMonomorphic = isEmptyVarSet . tyVarsOfType