Very cool. This is much nicer than when I asked much the same
question a few years back (and I can think of all sorts of
interesting things I can learn from the interface in that module).
But what about indirection chasing? Surely we want isWHNF to
return True if we have an indirection to a WHNF. Possibly one
wants something a bit like this (untested, and rather depends on
GHC's indirection semantics):
removingIndirections :: (forall c . c -> IO b) -> a -> IO b
removingIndirections k a = do
closureData <- getClosureData a
if isConstr (tipe closureData) then
removingIndirections (ptrs closureData ! 0)
else
k a
simpleIsWHNF :: a -> IO Boolean
simpleIsWHNF = fmap (isConstr . tipe) . getClosureData
isWHNF = removingIndirections simpleIsWHNF
Very true, isWHNF needs to follow indirections indeed. To decide
whether to recurse, you probably intended to test for Indirections
and not for Constructors:
removingIndirections :: (forall c . c -> IO b) -> a -> IO b
removingIndirections k a = do
closureData <- getClosureData a
if isIndirection (tipe closureData) then
removingIndirections (ptrs closureData ! 0)
else
k a
Thanks,
pepe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe