Hi,
Does anyone know if there is a function that tells you if a haskell
value has been forced or not?
e.g.
isWHNF :: a - IO Bool
let x = (map succ [0..]) in do
putStrLn . show (isWHNF x)-- False
putStrLn . show . head $ x
putStrLn . show (isWHNF x)-- True
Hi Tristan,
I've implemented it for earlier versions of GHC, by calling some C
code which then peeps at the internal representation of a value.
From memory, I needed to pass a stable pointer to the value to the C
code, so that it can be polymorphic, without having to make it a
primitive
Actually, in 6.8 we can build isWHNF on top of the GHC-API.
First, you need to import the ghc package:
ghci -package ghc
GHCi, version 6.7: http://www.haskell.org/ghc/ :? for help
Then, you can define the isWHNF function as follows:
Prelude :m +RtClosureInspect
Prelude RtClosureInspect
On Sep 27, 2007, at 9:14 AM, Pepe Iborra wrote:
Actually, in 6.8 we can build isWHNF on top of the GHC-API.
First, you need to import the ghc package:
ghci -package ghc
GHCi, version 6.7: http://www.haskell.org/ghc/ :? for help
Then, you can define the isWHNF function as follows:
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