[Haskell-cafe] Defining instance needs allow-undecidable-instance?

Daniel McAllansmith dagda at xtra.co.nz
Mon Mar 27 18:12:38 EST 2006


Hi, folks.

I've got a working class and instances thereof.  I would now like to change 
the class such that error behaviour is specified by MonadError, for the 
moment throwing String errors.  When I try to add MonadError into the types I 
eventually hit the requirement for allow-undecidable-instances.  
Is there some way I can I avoid having to use this extension?


My starting point consists of:

class (Num i, Bounded i, Monad m) => MonadSource i m | m -> i where
    ...

newtype SourceT i m a = SourceT (StateT (Store i) m a)
    deriving (Functor, Monad, MonadIO, MonadTrans)

instance (Num i, Bounded i, Monad m) => MonadSource i (SourceT i m) where
    ...

I changed it to:

class (Num i, Bounded i, Monad m, MonadError String m)
        => MonadSource i m | m -> i where
    ....

newtype SourceT i m a = SourceT (StateT (Store i) m a)
        deriving (Functor, Monad, MonadIO, MonadTrans, MonadError e)

instance (Num i, Bounded i, Monad m, MonadError String m)
        => MonadSource i (SourceT i m) where
    ...



Thanks
Daniel


More information about the Haskell-Cafe mailing list