EqInst related clean up
[ghc-hetmet.git] / compiler / typecheck / Inst.lhs
index c4cf7e1..13b8be8 100644 (file)
@@ -6,6 +6,13 @@
 The @Inst@ type: dictionaries or method instances
 
 \begin{code}
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
 module Inst ( 
        Inst, 
 
@@ -41,7 +48,7 @@ module Inst (
 
        mkWantedCo, mkGivenCo,
        fromWantedCo, fromGivenCo,
-       eitherEqInst, mkEqInst, mkEqInsts,
+       eitherEqInst, mkEqInst, mkEqInsts, mkWantedEqInst,
        finalizeEqInst, writeWantedCoercion,
        eqInstType, updateEqInstCoercion,
        eqInstCoercion,
@@ -972,11 +979,10 @@ fromWantedCo :: String -> Either TcTyVar Coercion -> TcTyVar
 fromWantedCo _ (Left covar) = covar
 fromWantedCo msg _         = panic ("fromWantedCo: not a wanted coercion: " ++ msg)
 
-eitherEqInst 
-       :: Inst                 -- given or wanted EqInst
-       -> (TcTyVar  -> a)      --      result if wanted
-       -> (Coercion -> a)      --      result if given
-       -> a            
+eitherEqInst :: Inst               -- given or wanted EqInst
+            -> (TcTyVar  -> a)     --  result if wanted
+            -> (Coercion -> a)     --  result if given
+            -> a               
 eitherEqInst (EqInst {tci_co = either_co}) withWanted withGiven
        = case either_co of
                Left  covar -> withWanted covar
@@ -997,6 +1003,12 @@ mkEqInst (EqPred ty1 ty2) co
             }
        where mkName uniq src_span = mkInternalName uniq (mkVarOcc "co") src_span
 
+mkWantedEqInst :: PredType -> TcM Inst
+mkWantedEqInst pred@(EqPred ty1 ty2)
+  = do { cotv <- newMetaTyVar TauTv (mkCoKind ty1 ty2)
+       ; mkEqInst pred (Left cotv)
+       }
+
 -- type inference:
 --     We want to promote the wanted EqInst to a given EqInst
 --     in the signature context.