
Hi again, Simon Peyton-Jones writes:
Don't try to get the type environment out. Instead, look at the syntax tree produced by the type checker. Each binder is an Id. There's a function idType :: Id -> Type that tells you the type of each binder. Quite how you present it to the user in a good way isn't clear to me,
Thanks Simon. In TcModule.lhs I added some code like this: myDumpTc results = myPprMonoBinds $ tc_binds results where myPprMonoBinds (AndMonoBinds b1 b2) = myPprMonoBinds b1 $$ myPprMonoBinds b2 myPprMonoBinds (FunMonoBind id _ matches _) = (ppr (toRdrName id)) <+> dcolon <+> (ppr $ idType id) $$ myPprMatches matches {- etc, etc ... -} For the following contrived example: main = putStr $ show (fred 1 3) where fred a b = let myid x = x in myid (plus a b) plus x y = x + y My output is: main :: IO () plus :: a -> a -> a fred :: a -> a -> a myid :: t_aMv -> t_aMv Which is nearly exactly what I want, however, the class constraints are missing from the signatures for plus and fred. The universal quantification of the type variable t_aMv is also missing. One curiosity is that the compiler has generated the variable 'a' in the two circumstances where the variables are constrained, which makes me think something special is happening here. If you defined all the binders at the top-level and supplied the -ddump-types flag to ghc (with a modification to the code to turn off the conversion to HsType, so that the unique variable names do not get clobbered) you get the proper polymorphic type signatures for each of the identifiers (ie myid :: forall t_aMv . t_aMv -> t_aMv). My question is: can I find out any information about the constraints on variables from the types that I find in the tc_binds component of the type checking results? (apologies for my being long-winded). Regards, Bernie.
participants (1)
-
Bernard James POPE