MonadError and fundeps

Marcin 'Qrczak' Kowalczyk
Fri, 11 May 2001 14:14:24 +0200 (CEST)

On Fri, 11 May 2001, Lauri Alanko wrote:

> Why? This makes composing and "subtyping" impossible:
> instance (MonadTrans t, MonadState s m, Monad (t m)) 
> 	 => MonadState s (t m) where
>     get = lift get
>     put = lift . put

This instance is illegal anyway. One of types in the instance head must be
a type constructor applied to something (type variables in Haskell 98,
anything with -fglasgow-exts).

Even if it was legal, it would overlap with
    instance Monad m => MonadState s (StateT s m)

Also MonadReader and MonadWriter can't have such generic instances anyway
because their methods have values of type 'm a' as arguments.

OTOH without the fundep there are ambiguities. For example:

class ParsingState s where
    stateInput :: s -> String
    stateSkip  :: Int -> s -> s

instance ParsingState String where ...
instance ParsingState s => ParsingState (s, Pos) where ...

input :: (ParsingState s, MonadState s m) => m String
         -- Ambiguous without the fundep.
input = gets stateInput

Marcin 'Qrczak' Kowalczyk