[Haskell-cafe] isWHNF :: a -> IO Bool ?
Pepe Iborra
mnislaih at gmail.com
Thu Sep 27 11:44:23 EDT 2007
> 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
More information about the Haskell-Cafe
mailing list