Inst(..), -- Visible only to TcSimplify
InstOrigin(..), OverloadedLit(..),
Inst(..), -- Visible only to TcSimplify
InstOrigin(..), OverloadedLit(..),
- LIE(..), emptyLIE, unitLIE, plusLIE, consLIE, zonkLIE,
+ LIE(..), emptyLIE, unitLIE, plusLIE, consLIE, zonkLIE, plusLIEs,
import TcHsSyn ( TcIdOcc(..), TcExpr(..), TcIdBndr(..),
mkHsTyApp, mkHsDictApp )
import TcHsSyn ( TcIdOcc(..), TcExpr(..), TcIdBndr(..),
mkHsTyApp, mkHsDictApp )
import TcEnv ( tcLookupGlobalValueByKey )
import TcType ( TcType(..), TcRhoType(..), TcMaybe, TcTyVarSet(..),
tcInstType, tcInstTcType, zonkTcType )
import TcEnv ( tcLookupGlobalValueByKey )
import TcType ( TcType(..), TcRhoType(..), TcMaybe, TcTyVarSet(..),
tcInstType, tcInstTcType, zonkTcType )
-import Bag ( Bag, emptyBag, unitBag, unionBags, listToBag, consBag )
-import Class ( Class(..), GenClass, ClassInstEnv(..), getClassInstEnv )
+import Bag ( emptyBag, unitBag, unionBags, unionManyBags, listToBag, consBag )
+import Class ( Class(..), GenClass, ClassInstEnv(..), classInstEnv )
import Id ( GenId, idType, mkInstId )
import MatchEnv ( lookupMEnv, insertMEnv )
import Id ( GenId, idType, mkInstId )
import MatchEnv ( lookupMEnv, insertMEnv )
import Outputable
import PprType ( GenClass, TyCon, GenType, GenTyVar )
import PprStyle ( PprStyle(..) )
import Pretty
import Outputable
import PprType ( GenClass, TyCon, GenType, GenTyVar )
import PprStyle ( PprStyle(..) )
import Pretty
import SpecEnv ( SpecEnv(..) )
import SrcLoc ( SrcLoc, mkUnknownSrcLoc )
import Type ( GenType, eqSimpleTy,
import SpecEnv ( SpecEnv(..) )
import SrcLoc ( SrcLoc, mkUnknownSrcLoc )
import Type ( GenType, eqSimpleTy,
unitLIE inst = unitBag inst
plusLIE lie1 lie2 = lie1 `unionBags` lie2
consLIE inst lie = inst `consBag` lie
unitLIE inst = unitBag inst
plusLIE lie1 lie2 = lie1 `unionBags` lie2
consLIE inst lie = inst `consBag` lie
mk_dict u (clas, ty) = Dict u clas ty orig loc
dicts = zipWithEqual mk_dict new_uniqs theta
mk_dict u (clas, ty) = Dict u clas ty orig loc
dicts = zipWithEqual mk_dict new_uniqs theta
newDictsAtLoc orig loc theta -- Local function, similar to newDicts,
-- but with slightly different interface
newDictsAtLoc orig loc theta -- Local function, similar to newDicts,
-- but with slightly different interface
mk_dict u (clas, ty) = Dict u clas ty orig loc
dicts = zipWithEqual mk_dict new_uniqs theta
mk_dict u (clas, ty) = Dict u clas ty orig loc
dicts = zipWithEqual mk_dict new_uniqs theta
newMethod :: InstOrigin s
-> TcIdOcc s
-> [TcType s]
-> NF_TcM s (LIE s, TcIdOcc s)
newMethod orig id tys
newMethod :: InstOrigin s
-> TcIdOcc s
-> [TcType s]
-> NF_TcM s (LIE s, TcIdOcc s)
newMethod orig id tys
- = -- Get the Id type and instantiate it at the specified types
- (case id of
- RealId id -> let (tyvars, rho) = splitForAllTy (idType id)
- in tcInstType (tyvars `zipEqual` tys) rho
- TcId id -> let (tyvars, rho) = splitForAllTy (idType id)
- in tcInstTcType (tyvars `zipEqual` tys) rho
- ) `thenNF_Tc` \ rho_ty ->
-
- -- Our friend does the rest
- newMethodWithGivenTy orig id tys rho_ty
+ = -- Get the Id type and instantiate it at the specified types
+ (case id of
+ RealId id -> let (tyvars, rho) = splitForAllTy (idType id)
+ in tcInstType (tyvars `zipEqual` tys) rho
+ TcId id -> let (tyvars, rho) = splitForAllTy (idType id)
+ in tcInstTcType (tyvars `zipEqual` tys) rho
+ ) `thenNF_Tc` \ rho_ty ->
+ -- Our friend does the rest
+ newMethodWithGivenTy orig id tys rho_ty
newMethodAtLoc :: InstOrigin s -> SrcLoc -> Id -> [TcType s] -> NF_TcM s (Inst s, TcIdOcc s)
newMethodAtLoc orig loc real_id tys -- Local function, similar to newMethod but with
-- slightly different interface
newMethodAtLoc :: InstOrigin s -> SrcLoc -> Id -> [TcType s] -> NF_TcM s (Inst s, TcIdOcc s)
newMethodAtLoc orig loc real_id tys -- Local function, similar to newMethod but with
-- slightly different interface
- = -- Get the Id type and instantiate it at the specified types
- let
- (tyvars,rho) = splitForAllTy (idType real_id)
- in
- tcInstType (tyvars `zipEqual` tys) rho `thenNF_Tc` \ rho_ty ->
- tcGetUnique `thenNF_Tc` \ new_uniq ->
- let
+ = -- Get the Id type and instantiate it at the specified types
+ let
+ (tyvars,rho) = splitForAllTy (idType real_id)
+ in
+ tcInstType (tyvars `zipEqual` tys) rho `thenNF_Tc` \ rho_ty ->
+ tcGetUnique `thenNF_Tc` \ new_uniq ->
+ let
newOverloadedLit :: InstOrigin s
-> OverloadedLit
-> TcType s
-> NF_TcM s (LIE s, TcIdOcc s)
newOverloadedLit orig lit ty
newOverloadedLit :: InstOrigin s
-> OverloadedLit
-> TcType s
-> NF_TcM s (LIE s, TcIdOcc s)
newOverloadedLit orig lit ty
-instToId (Dict uniq clas ty orig loc)
- = TcId (mkInstId uniq (mkDictTy clas ty) (mkShortName SLIT("dict") loc))
-instToId (Method uniq id tys rho_ty orig loc)
- = TcId (mkInstId uniq tau_ty (mkShortName (getOccurrenceName id) loc))
+instToId (Dict u clas ty orig loc)
+ = TcId (mkInstId u (mkDictTy clas ty) (mkLocalName u SLIT("dict") loc))
+instToId (Method u id tys rho_ty orig loc)
+ = TcId (mkInstId u tau_ty (mkLocalName u (getLocalName id) loc))
OverloadedIntegral i -> ppInteger i
OverloadedFractional f -> ppRational f,
OverloadedIntegral i -> ppInteger i
OverloadedFractional f -> ppRational f,
maybe_spec_info (_, match_info, MkInstTemplate dfun _ [])
= Just (SpecInfo (map (assocMaybe match_info) inst_tvs) (length inst_theta) dfun)
maybe_spec_info (_, match_info, MkInstTemplate dfun _ [])
= Just (SpecInfo (map (assocMaybe match_info) inst_tvs) (length inst_theta) dfun)
= OccurrenceOf (TcIdOcc s) -- Occurrence of an overloaded identifier
| OccurrenceOfCon Id -- Occurrence of a data constructor
= OccurrenceOf (TcIdOcc s) -- Occurrence of an overloaded identifier
| OccurrenceOfCon Id -- Occurrence of a data constructor
| InstanceDeclOrigin -- Typechecking an instance decl
| LiteralOrigin HsLit -- Occurrence of a literal
| InstanceDeclOrigin -- Typechecking an instance decl
| LiteralOrigin HsLit -- Occurrence of a literal
= ppBesides [ppStr "in a `deriving' clause; class `",
ppr sty clas,
ppStr "'; offending type `",
ppr sty tycon,
ppStr "'"]
= ppBesides [ppStr "in a `deriving' clause; class `",
ppr sty clas,
ppStr "'; offending type `",
ppr sty tycon,
ppStr "'"]
= ppBesides [ppStr "in a SPECIALIZE instance pragma; class \"",
ppr sty clas, ppStr "\" type: ", ppr sty ty]
= ppBesides [ppStr "in a SPECIALIZE instance pragma; class \"",
ppr sty clas, ppStr "\" type: ", ppr sty ty]
= ppBesides [ppStr "in an argument in the _ccall_ to `",
ppStr clabel, ppStr "', namely: ", ppr sty arg_expr]
= ppBesides [ppStr "in an argument in the _ccall_ to `",
ppStr clabel, ppStr "', namely: ", ppr sty arg_expr]