<div dir="ltr">A related data type that I've made use of in the past is described here<div><br></div><div><a href="https://www.fpcomplete.com/user/edwardk/snippets/once">https://www.fpcomplete.com/user/edwardk/snippets/once</a><br></div><div><br></div><div>This version has the benefit that it works with data that really does need a deepSeq, but encapsulates it in such a way that subsequent deepSeq's do no extra work.</div><div><br></div><div>-Edward</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 10, 2015 at 3:46 AM, Edward Z. Yang <span dir="ltr"><<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I propose the following (abstract) data type, functions, and instance be<br>
added to deepseq (naming amenable to bikeshedding):<br>
<br>
    newtype NF a = NF a -- abstract<br>
    makeNF :: NFData a => a -> NF a<br>
    getNF :: NF a -> a<br>
    instance NFData (NF a) where<br>
        rnf x = x `seq` ()<br>
<br>
NF is an abstract data type representing data which has been evaluated<br>
to normal form; the guarantee specifically is, if NF is in whnf, then<br>
it is in nf.  Crucially, when we have 'NF a', we ONLY need to seq it<br>
in order to assure that it is fully evaluated.<br>
<br>
This guarantee is sufficient for a variety of cases where<br>
normal data is necessary, e.g. when transmitting data over Channels.<br>
For example, from the monad-par library 'put_' could be used in place<br>
of 'put' with this type signature.<br>
<br>
    put_ :: IVar (NF a) -> (NF a) -> Par ()<br>
<br>
Cheers,<br>
Edward<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</blockquote></div><br></div>