Then if you turn :
fs True = True
fs x = True
to:
fs x = case x of
True -> True
x' -> True
Is it still strict, or does 'fs' wrap the case test and defer evaluation?
2011/4/1 <[email protected]>
>
> Daniel Fischer wrote:
> > If you have a strict function, you may evaluate its argument eagerly
> > without changing the result^1, while eager evaluation of a non-strict
> > function's argument may produce _|_ where deferred evaluation wouldn't.
>
> Sadly, that is quite untrue. Strictness is observable, already in
> Haskell98. That distressing result has nothing to do with imprecise
> exceptions, seq, non-termination, lack of resources, or the use of
> unsafe features. Plainly, just by changing the strictness of a
> function one may cause the program to print different results, such as
> "strict" or "non-strict" in the code below.
>
> -- Haskell98!
> -- Strictness is observable
> -- With no seq, no unsafe operations
>
> import Control.Exception
>
> -- fs and fns are both essentially (const True) functions,
> -- but differ in strictness
> fs,fns :: Bool -> Bool
>
> -- non-strict
> fns x = True
>
> -- strict
> fs True = True
> fs x = True
>
>
> handler :: SomeException -> IO ()
> handler _ = print "strict"
>
> test f = handle handler $
> if f (error "Bang!") then print "non-strict" else return ()
>
> main_s = test fs
> -- prints "strict"
>
> main_ns = test fns
> -- prints "non-strict"
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe