nf-1.0.1.0: NF data type to statically enforce normal form

Copyright(c) Stanford University 2015
LicenseBSD-style (see the file LICENSE)
Maintainerezyang@cs.stanford.edu
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Data.NF

Description

This module provides a data type, NF, representing data which has been evaluated to "Normal Form". This is a useful type discipline for many situations when normal form data is necessary, e.g. when transmitting data to other threads over channels. If a library that you are using has the following type:

strictWriteChan :: NFData a => Chan a -> a -> IO ()

you can specialize it to the following type in order to avoid the cost of repeatedly deepseqing a value when it is not necessary:

strictWriteChan_ :: Chan (NF a) -> NF a -> IO ()
strictWriteChan_ = strictWriteChan

You should also consider providing APIs which only accept NF values, to prevent users from accidentally deepseqing.

Synopsis

Documentation

data NF a Source

NF is an abstract data type representing data which has been evaluated to normal form. Specifically, if a value of type NF a is in weak head normal form, then it is in reduced normal form; alternatively, it is only necessary to seq an NF a to assure that it is fully evaluated.

Instances

Eq a => Eq (NF a) 
Ord a => Ord (NF a) 
NFData (NF a) 
Typeable (* -> *) NF 

makeNF :: NFData a => a -> NF a Source

Creates a value of type NF. The first time the result is evaluated to whnf, the value will be rnfed. To avoid this rnf, see UnsafeNF.

getNF :: NF a -> a Source

Retrieves a from a value of type NF a; this value is guaranteed to be in normal form.