types from ghc (another question)

Simon Peyton-Jones [email protected]
Mon, 20 Nov 2000 01:50:31 -0800


Bernie

All (I think) the top level bindings come out of the type check
as an AbsBinds.  This is where we generalise from a monomorphic
thing to a polymorphic thing.

An AbsBinds has four components, the third of which is a list of
triples (TyVar, Id, Id).  You want to grab the first of these Ids (only).
You can then ignore the MonoBinds inside the fourth component of
the AbsBinds.  So your code will get quite a bit simpler.

The two Ids in the triple are the polymorphic top-level binder and
the monomorphic (perhaps recursive) thing that it generalises.
It's a bit hard to explain in a short space.  Look at the output of the 
desugarer for a simple defn, to see what an AbsBinds translates to.

Anyway these polymorphic Ids will have exactly the for-alls and
constraints that you want

hope this gets you moving


Simon

| -----Original Message-----
| From: Bernard James POPE [mailto:[email protected]]
| Sent: 19 November 2000 07:34
| To: [email protected]
| Cc: [email protected]
| Subject: types from ghc (another question)
| 
| 
| 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.
| 
| _______________________________________________
| Glasgow-haskell-users mailing list
| [email protected]
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
|