how frowned-upon is "recursive coreView"?
Simon Peyton-Jones
simonpj at microsoft.com
Mon Feb 21 17:02:09 CET 2011
The only reason this is bad is that in GHC a function only has one type. So suppose
f :: forall a. Eq a => a -> a
(which is just surface syntax for
ForAllTY a (FunTy (PredTy (ClassP Eq [a])) ...)
)
If you change that to
f :: forall a. DEq a -> a -> a
where DEq is the data type of the dictionary rep for (Eq a) predicate,
then everything will be fine except that module that *import* this module won't realise that the DEq parameter is a type-class parameter. The PredTy stuff serves to tell the type checker which parameters are implict to be elaborated by type inference
S
| -----Original Message-----
| From: cvs-ghc-bounces at haskell.org [mailto:cvs-ghc-bounces at haskell.org] On
| Behalf Of Adam Megacz
| Sent: 18 February 2011 22:48
| To: cvs-ghc at haskell.org
| Subject: how frowned-upon is "recursive coreView"?
|
|
| The function at the end of this email walks over a Type, basically
| (recursivey) replacing it with its coreView. The resulting tree has no
| PredTy's except for (PredTy (EqPred _ _)).
|
| How problematic is it for a core-to-core translation to replace all the
| Type's in an Expr with their coreView-ification this way? Is it likely
| to cause compilation/core-lint failures, or is it just ugly?
|
| I suppose that at the very least it makes it harder to debug passes
| which happen after the coreView-ifying pass. And I realize that
| actually replacing a type with its coreView (rather than calling
| coreView "on demand") is not the preferred way of doing things.
|
| Thanks,
|
| - a
|
| coreViewDeep :: Type -> Type
| coreViewDeep t =
| case t of
| TyVarTy tv -> TyVarTy tv
| FunTy arg res -> FunTy (coreViewDeep arg) (coreViewDeep res)
| AppTy fun arg -> AppTy (coreViewDeep fun) (coreViewDeep arg)
| ForAllTy fun arg -> ForAllTy fun (coreViewDeep arg)
| TyConApp tc tys -> let t' = TyConApp tc (map coreViewDeep tys)
| in case coreView t' of
| Nothing -> t'
| Just t'' -> t''
| PredTy p -> case coreView t of
| Nothing -> PredTy p
| Just t' -> t'
|
|
|
| _______________________________________________
| Cvs-ghc mailing list
| Cvs-ghc at haskell.org
| http://www.haskell.org/mailman/listinfo/cvs-ghc
More information about the Cvs-ghc
mailing list