Proposal: NF newtype

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue Feb 10 09:24:23 UTC 2015


On 10 February 2015 at 19:46, Edward Z. Yang <ezyang at mit.edu> wrote:
> I propose the following (abstract) data type, functions, and instance be
> added to deepseq (naming amenable to bikeshedding):
>
>     newtype NF a = NF a -- abstract
>     makeNF :: NFData a => a -> NF a
>     getNF :: NF a -> a
>     instance NFData (NF a) where
>         rnf x = x `seq` ()

What about also adding `unsafeMakeNF :: a -> NF a` for times when you
may have already made a value into normal form?

Either way, +1.

>
> NF is an abstract data type representing data which has been evaluated
> to normal form; the guarantee specifically is, if NF is in whnf, then
> it is in nf.  Crucially, when we have 'NF a', we ONLY need to seq it
> in order to assure that it is fully evaluated.
>
> This guarantee is sufficient for a variety of cases where
> normal data is necessary, e.g. when transmitting data over Channels.
> For example, from the monad-par library 'put_' could be used in place
> of 'put' with this type signature.
>
>     put_ :: IVar (NF a) -> (NF a) -> Par ()
>
> Cheers,
> Edward
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries



-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Libraries mailing list