Type of an HsExpr

Ranjit Jhala jhala at cs.ucsd.edu
Wed May 25 02:14:29 CEST 2011

> (My application is a haskell to java compiler, btw;
> I need the type for the proper use of generics in java.)

In that case why not just use the types attached with the CoreExprs? 


Just use GHC to crunch your haskell source to Core, and then use exprType?

I have been wrestling with a similar issue (extracting source
level types with minimal effort) a much simpler setting. The 
hack I use is to tweak the deSugaring process to add SrcSpan 
to each desugared expression:

1. I've added a "CoreLoc SrcSpan" constructor to the Note type

2. I've changed:  dsLExpr so that it wraps a SrcSpan around the desugared expression

3. Now you can walk over the final CoreExpr, and build a map from SrcSpan -> Type 
   (exprType gives you the type of each coreExpr), and when you "join" that with 
   Source-Expression-SrcSpan map then you should get the types of the (located) 
   expressions ...

Its a total hack but it allows one to operate only with the simple CoreExprs :)

> Thanks again,
> Sven
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

More information about the Glasgow-haskell-users mailing list