
I'd like to see a way of enforcing return strictness, that is where you have confidence that what a function is returning is fully evaluated. Imagine a function hstrict; hstrict :: a -> a you can define hseq with this. hseq :: a -> b -> b hseq a b = hstrict a `seq` b and $!!. ($!!) :: (a -> b) -> a -> b a $!! b = a $! (hstrict b) With hstrict you can write functions in the style. fun f a b c = hstrict $ .... where ... ... and also fun f a b c = hstruct $ bla { abc = def , cfg = tts , ... } We know that strictness plays no part in the returned value after the function is finished evaluating, which is a Useful Property. What I'd like is a efficient hstrict, that does not re-evaluate anything that has already been hstrict-ified. In the same way as we evaluate an object, we could strictify an object using a similar (low-level) mechanism. So the cost of calling hstrict would be amortized away to almost nothing. How much work would this be to add hstrict GHC? A extra bit in the runtime representation? Could we use the speculation mechanism to do it? Andy Gill

Andy Gill wrote:
I'd like to see a way of enforcing return strictness, that is where you have confidence that what a function is returning is fully evaluated.
Imagine a function hstrict;
hstrict :: a -> a
Is this like deepseq, that strictly evaluates internal structure using seq?
With hstrict you can write functions in the style.
fun f a b c = hstrict $ .... where ... ...
But surely fun can return the unevaluated thunk (hstrict x)? Since hstrict has not yet been called, it can't do its strictifying magic, whatever that is. -- Ashley Yakeley

On Feb 17, 2006, at 3:30 PM, Ashley Yakeley wrote:
Andy Gill wrote:
I'd like to see a way of enforcing return strictness, that is where you have confidence that what a function is returning is fully evaluated. Imagine a function hstrict; hstrict :: a -> a
Is this like deepseq, that strictly evaluates internal structure using seq?
yes. it is.
With hstrict you can write functions in the style. fun f a b c = hstrict $ .... where ... ...
But surely fun can return the unevaluated thunk (hstrict x)? Since hstrict has not yet been called, it can't do its strictifying magic, whatever that is.
No. hstrict will always be called before returning. Evaluation does not return thunks, they get created by lets/where (at the core level), not by function application/evaluation. Andy Gill
participants (2)
-
Andy Gill
-
Ashley Yakeley