[Haskell-cafe] isWHNF :: a - IO Bool ?

2007-09-27 Thread Tristan Allwood
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

Re: [Haskell-cafe] isWHNF :: a - IO Bool ?

2007-09-27 Thread Bernie Pope
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

Re: [Haskell-cafe] isWHNF :: a - IO Bool ?

2007-09-27 Thread Pepe Iborra
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

Re: [Haskell-cafe] isWHNF :: a - IO Bool ?

2007-09-27 Thread Jan-Willem Maessen
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:

Re: [Haskell-cafe] isWHNF :: a - IO Bool ?

2007-09-27 Thread Pepe Iborra
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