Proposal: NF newtype

Herbert Valerio Riedel hvr at gnu.org
Tue Feb 10 11:41:41 UTC 2015


On 2015-02-10 at 09:46:37 +0100, Edward Z. Yang 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` ()

I generally like it, so count me as +1 

bikeshed-wondering though, why did you make it abstract w/ separate
construct/deconstructors?


as a related concept (and hoping not to derail the discussion too much),
I had attempted some time ago to implement TH predicates  that could
infer if WHNF=NF holds:

 http://hackage.haskell.org/package/deepseq-th-0.1.0.4/docs/Control-DeepSeq-TH.html#v:typeWhnfIsNf

and back then I was wondering, if GHC couldn't help us out here (maybe
by providing an implicit NF=WHNF class-instance -- and btw, I recently
found out, Haskell 1.4 had an implicit 'Eval'-class declaring
`seq`-ability)

I'm not sure though if WHNF=NF can always be decided...


Cheers,
  hvr


More information about the Libraries mailing list