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

Roman Cheplyaka roma at ro-che.info
Wed Jul 1 14:38:04 UTC 2015

On 01/07/15 17:10, Hemanth Kapila wrote:
> Hi,
> 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
> SomeException)*
> 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?

Here are a couple of references:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150701/40e7982b/attachment.sig>

More information about the Haskell-Cafe mailing list