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

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Thu Sep 27 11:59:47 EDT 2007


apfelmus <apfelmus at quantentunnel.de> writes:

> Tristan Allwood wrote:
>> 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
>
> Note that this function is not referentially transparent since
>
>   isWHNF 2 = True
>
> but
>
>   isWHNF (1+1) = False
>
> although 1+1 = 2. In other words, it messes up the language
> semantics (extensional equality) which is bad.

Isn't it OK if it's a -> IO Bool ? (Admittedly, the test
example above is wrong in that case).

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk



More information about the Haskell-Cafe mailing list