[Haskell-cafe] GHCi infers a type but refuses it as type signature

Wei Hu wei.hoo at gmail.com
Thu Jun 25 14:51:42 EDT 2009


On Thu, Jun 25, 2009 at 1:10 PM, David Menendez<dave at zednenem.com> wrote:
> On Thu, Jun 25, 2009 at 12:17 PM, Wei Hu<wei.hoo at gmail.com> wrote:
>> Could you or anyone else briefly explain how mmtl solves the
>> combinatorical explosion problem? Reading the source code is not very
>> productive for newbies like me. Thanks!
>
> It's a good question, since from what I can tell mmtl does not solve
> the problem.
>
> Some quick background: If you have M monad transformers and N classes
> of operations, you normally need M*N instance declarations, i.e., one
> per transformer per class. Each instance either provides the
> functionality directly, such as the MonadState instance for StateT, or
> promotes it from the underlying monad, such as the MonadState instance
> for ReaderT.
>
> mmtl instead provides 2*M instances. For each transformer, it has one
> direct instance (such as MonadState (StateT s m)) and one instance
> which promotes through any transformer (such as MonadState (t (StateT
> s m))).
>
> The problem is that this limits you to using at most two transformers
> at a time. For example, the type ErrorT String (ReaderT Int (StateT
> Int m)) is an instance of MonadError and MonadReader, but not
> MonadState because it doesn't have the form t (StateT s m).
>
> --
> Dave Menendez <dave at zednenem.com>
> <http://www.eyrie.org/~zednenem/>
>


Very well explained. Thanks.


More information about the Haskell-Cafe mailing list