[Haskell-cafe] A datatype with a single constructor and forall to multiple constructors without forall

Hemanth Kapila saihemanth at gmail.com
Wed Jul 1 14:10:14 UTC 2015


Occassionally, in (*good*) haskell libraries, I came across data types that
are defined with a single constructor and a forall.

For instance, Iteratee[0] is defined as below

*newtype Iteratee s m a =*
*    Iteratee {runIter :: forall r. (a -> Stream s -> m r) -> ((Stream s ->
Iteratee s m a) -> Maybe SomeException -> m r) -> m r}*

I *think* it is equivalent to the following. But am not sure.
*data Iteratee s m a  = IOne (m (a , Stream s))*
*                 | ITwo (Stream s -> m (Iteratee s m a)) (Maybe

Can some one please explain what are the advantages of using the forall
version? Does it significantly improve performance because it is newtype?
Or does it help in reasoning about code (in some proof tools or such)?

And can some one kindly point me to some references that help me  convert
from one form to another reliably?

Many Thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150701/492f10ab/attachment.html>

More information about the Haskell-Cafe mailing list