[project @ 2000-11-16 09:51:31 by simonmar]
authorsimonmar <unknown>
Thu, 16 Nov 2000 09:51:31 +0000 (09:51 +0000)
committersimonmar <unknown>
Thu, 16 Nov 2000 09:51:31 +0000 (09:51 +0000)
merge rev. 1.66.2.6 (add splitMethodTy)

ghc/compiler/types/Type.lhs

index bc2d94c..7ef2765 100644 (file)
@@ -56,7 +56,7 @@ module Type (
        TauType, RhoType, SigmaType, PredType(..), ThetaType,
        ClassPred, ClassContext, mkClassPred,
        getClassTys_maybe, ipName_maybe, classesOfPreds,
-       isTauTy, mkRhoTy, splitRhoTy,
+       isTauTy, mkRhoTy, splitRhoTy, splitMethodTy,
        mkSigmaTy, isSigmaTy, splitSigmaTy,
        getDFunTyKey,
 
@@ -773,6 +773,26 @@ splitRhoTy ty = split ty ty []
   split orig_ty ty             ts = (reverse ts, orig_ty)
 \end{code}
 
+The type of a method for class C is always of the form:
+       Forall a1..an. C a1..an => sig_ty
+where sig_ty is the type given by the method's signature, and thus in general
+is a ForallTy.  At the point that splitMethodTy is called, it is expected
+that the outer Forall has already been stripped off.  splitMethodTy then
+returns (C a1..an, sig_ty') where sig_ty' is sig_ty with any Notes or
+Usages stripped off.
+
+\begin{code}
+splitMethodTy :: Type -> (PredType, Type)
+splitMethodTy ty = split ty
+ where
+  split (FunTy arg res) = case splitPredTy_maybe arg of
+                           Just p  -> (p, res)
+                           Nothing -> panic "splitMethodTy"
+  split (NoteTy _ ty)  = split ty
+  split (UsageTy _ ty)  = split ty
+  split _               = panic "splitMethodTy"
+\end{code}
+
 
 isSigmaType returns true of any qualified type.  It doesn't *necessarily* have 
 any foralls.  E.g.