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

Bernie Pope bjpop at csse.unimelb.edu.au
Thu Sep 27 08:51:30 EDT 2007

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 in GHC.

Have a look at the "reify" code on this page: http://www.cs.mu.oz.au/ 
~bjpop/code.html - its more than what you want, but you can trim it  
down easily.
Let me know if you get stuck.

The internal representation in GHC tends to change between releases,  
so it might need a bit of polishing up.


On 27/09/2007, at 10:07 PM, Tristan Allwood wrote:

> 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
>   putStrLn . show (isWHNF (Just undefined)) -- True
> If not, would it be hard/easy/possible to implement on-top-of or using
> GHC?  I'm happy (if it's possible) to have a stab at implementing it
> myself, so any pointers to right directions would be helpful.
> I'm thinking it could be useful to allow creation of sparse-check [1]
> like libraries without needing a separate logic encoding, or things
> along those lines / in that area.
> Cheers,
> Tris
> [1] http://www-users.cs.york.ac.uk/~mfn/sparsecheck/index.html#lim
> -- 
> Tristan Allwood
> PhD Student
> Department of Computing
> Imperial College London
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list