How to get types including constraints out of TypecheckedModule

Simon Peyton Jones simonpj at microsoft.com
Fri Sep 25 07:42:29 UTC 2015


|  What if I have a binder:
|  
|      (foo, bar) = (show, show)
|  
|  I can now get the polymorphic types of foo and bar respectively but
|  how do I'm not sure how I'm meant to zip up the monomorphic type of
|  `pat_rhs_ty`, i.e. the type of the whole rhs, with the polymorphic
|  types in `abs_exports`.
|  
|  I mean I could just match up the type variables and pull the
|  constraints in by hand but it just seems like there already ought to
|  be a way to do this somewhere?

I'm sorry I don't understand the question.  For the above pattern binding you'll get something like

   AbsBinds {
      abe_tvs = [a,b]
      abe_ev_vars = [ d1 :: Show a, d2 :: Show b ]
      
      abe_exports = [
        ABE { abe_poly = foo :: forall a. Show a => a->String
            , abe_mono = foo_m :: a->String
            , abe_wrap = ... }
        ABE { abe_poly :: bar :: forall b. Show b => b->String
              abe_mono = bar_m :: b->String 
              ... }
        ]
  
     abe_binds = { (foo_m, bar_m) = (show a d1, show b d2) }
   }

Simon
|  
|  Alternatively my strategy to do this would be to build a map from
|  TyVar to the constraint and then going over the monomorphic types and
|  for each TyVar that's mentioned in the monomorphic type pull in the
|  relevant constraint and apply those to the monomorphic type. Does that
|  sound sensible at all? I have no idea how equality constraints and all
|  that fancy stuff are encoded so I hope that doesn't need any special
|  handling ;)
|  
|  > I hope this is of some help.  If so, would you like to update the
|  > Commentary (on the GHC wiki) to add the information you wish had
|  been
|  > there in the first place?  Thanks!
|  
|  Very much so, thanks :)
|  
|  I'd love to put this in the commentary somewhere but looking at
|  https://ghc.haskell.org/trac/ghc/wiki/Commentary I can't actually find
|  anywhere this would fit in and it just seems like an awefully specific
|  thing to put there. Maybe it would be better to improve the comments
|  instead for the next person that goes looking thoguth the source
|  trying to figure out where the types end up.
|  
|  For example the comment on AbsBinds could mention that this is where
|  the typechecker stores inferred constrainst or something like that.
|  
|  --Daniel


More information about the ghc-devs mailing list