[Haskell-cafe] Can not use ST monad with polymorphic function

David Menendez dave at zednenem.com
Sat Dec 1 21:09:44 CET 2012


On Thu, Nov 29, 2012 at 7:50 AM, Dmitry Kulagin <dmitry.kulagin at gmail.com>wrote:

> Thank you, MigMit!
>
> If I replace your type FoldSTVoid with:
> data FoldMVoid = FoldMVoid {runFold :: Monad m => (Int -> m ()) -> m ()}
>
> then everything works magically with any monad!
> That is exactly what I wanted, though I still do not quite understand why
> wrapping the type solves the problem
>

Short answer: It's because GHC's type system is predicative.

Basically, quantified types can't be given as arguments to type
constructors (other than ->, which is its own thing). I'm not entirely sure
why, but it apparently makes the type system very complicated from a
theoretical standpoint. By wrapping the quantified type in a newtype, the
argument to IO becomes simple enough not to cause problems.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121201/dfe625be/attachment.htm>


More information about the Haskell-Cafe mailing list