- -> NF_TcM s ([Inst], [TcId])
-newDictsAtLoc loc theta =
- tcGetUniques (length theta) `thenNF_Tc` \ new_uniqs ->
- let
- mk_dict u pred = Dict u pred loc
- dicts = zipWithEqual "newDictsAtLoc" mk_dict new_uniqs theta
- in
- returnNF_Tc (dicts, map instToId dicts)
+ -> NF_TcM [Inst]
+newDictsAtLoc inst_loc@(_,loc,_) theta
+ = tcGetUniques `thenNF_Tc` \ new_uniqs ->
+ returnNF_Tc (zipWith mk_dict new_uniqs theta)
+ where
+ mk_dict uniq pred = Dict (mkLocalId (mkPredName uniq loc pred) (mkPredTy pred)) pred inst_loc
+
+-- For implicit parameters, since there is only one in scope
+-- at any time, we use the name of the implicit parameter itself
+newIPDict orig name ty
+ = tcGetInstLoc orig `thenNF_Tc` \ inst_loc ->
+ returnNF_Tc (Dict (mkLocalId name (mkPredTy pred)) pred inst_loc)
+ where pred = IParam name ty
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Building methods (calls of overloaded functions)}
+%* *
+%************************************************************************
+
+tcInstId instantiates an occurrence of an Id.
+The instantiate_it loop runs round instantiating the Id.
+It has to be a loop because we are now prepared to entertain
+types like
+ f:: forall a. Eq a => forall b. Baz b => tau
+We want to instantiate this to
+ f2::tau {f2 = f1 b (Baz b), f1 = f a (Eq a)}
+
+The -fno-method-sharing flag controls what happens so far as the LIE
+is concerned. The default case is that for an overloaded function we
+generate a "method" Id, and add the Method Inst to the LIE. So you get
+something like
+ f :: Num a => a -> a
+ f = /\a (d:Num a) -> let m = (+) a d in \ (x:a) -> m x x
+If you specify -fno-method-sharing, the dictionary application
+isn't shared, so we get
+ f :: Num a => a -> a
+ f = /\a (d:Num a) (x:a) -> (+) a d x x
+This gets a bit less sharing, but
+ a) it's better for RULEs involving overloaded functions
+ b) perhaps fewer separated lambdas
+