brian at brianweb.net
Fri Jan 30 14:27:24 EST 2009
SPJ might be able to give you some better answers, but this should help
get you started.
On Fri, Jan 30, 2009 at 08:03:47PM +0100, Matthijs Kooijman wrote:
> However, there are two issues bothering me still. The first is that the
> Core types (in particular CoreExpr) are not instances of Show. They are
> instances of Outputable, which allows them to be pretty printed.
Making all GHC's datatypes Showable would probably be a nightmare. Not
only because of all the instances you'd have to add, but because many
of the datatypes have cycles in them (or example, DataCons point back
to their TyCon). Even if you got all the "derriving Show"s in there
you'd be stuck writing manual instances everywhere cycles appear. In
addition, the sheer amount of data GHC carries around in its various
data types would make the output pretty incomprehensable. For example,
every occurance of an identifier carries around unfolding info,
strictness info, arity, specializations, etc.
You're probably better off just trying to wrap your head around the
pretty printed output and using that. When you need to pull some more
details out of a datatype just sticking random pprPanics in is a great
> about this, in Core it's just a Var and the isDataConName [IIRC]
> predicate crashes when run on the Var).
You might be looking for isDataConId :: Id -> Bool, or
isDataConId_maybe :: Id -> Maybe DataCon.
> For now, I've manually matched the Var's name to GHC.Tuple.(,) and
> removed all type arguments to get at the actual values in the tuple.
> This is of course completely non-portable, to tuples with more than two
> elements, or unboxed tuples, etc.
You might find exprIsConApp_maybe :: CoreExpr -> Maybe (DataCon,[CoreExpr])
handy (along with isTupleCon :: DataCon -> Bool on the DataCon).
More information about the Glasgow-haskell-users