Copyright | (c) Stanford University 2015 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | ezyang@cs.stanford.edu |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
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 deepseq
ing 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 deepseq
ing.