types from ghc - got them!

Hi again, For my previous 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 I can now get the following output: ==================== Bernie: All Binder TypeSigs ==================== main :: IO () plus :: forall a. (Num a) => a -> a -> a fred :: forall a. (Num a) => a -> a -> a myid :: forall t_aMv. t_aMv -> t_aMv Which is exactly what I want. Turned out to be quite simple in the end. Thanks a lot for all your help Simon. Just out of curiosity, do you think that this sort of output would be useful for other people? I don't know what your plans are for GHCi, but you may be considering a mode that prints types out, something like :t in hugs. I always found it frustrating in hugs that I couldn't get the types of locally defined values. My students also find this frustrating, and it sometimes causes them to avoid local definitions. Obviously there are issues with type variables which are quantified outside the local definition, but careful naming of things should be able to fix this. Regards, Bernie. Simon Peyton-Jones writes:
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

On Tue, 21 Nov 2000, Bernard James POPE wrote:
Obviously there are issues with type variables which are quantified outside the local definition, but careful naming of things should be able to fix this.
Hi, For my master thesis I wrote a tool called Typeview (presented at IFL'00) that can display the types of arbitrary expressions (even in programs that are not typecorrect). We chose to append an underscore to every type variable that is not quantified at the examined expression: f :: a -> (a, Int) f x = let g y = (x,y) in g 3 In this program the type of the local expression is g:: b -> (_a,b). This approach could be used for local type annotations (and thereby replacing the pattern annotations), the :t command and error messages. Of course you have to make sure that _a is not ambiguous. Cheers, Axel.
participants (2)
-
Axel Simon
-
Bernard James POPE