I tried this: class MonadTrans' i o where lift' :: i a -> o a instance (MonadTrans t, Monad m) => MonadTrans' m (t m) where lift' = lift instance (MonadTrans' a b, MonadTrans' b c) => MonadTrans' a c where lift' = lift' . lift' And it doesn't work. I know what I want it to do, how do I express it right? -- Taral <taralx@gmail.com> "You can't prove anything." -- Gödel's Incompetence Theorem
On 3/13/07, Taral <taralx@gmail.com> wrote:
And it doesn't work. I know what I want it to do, how do I express it right?
This is closer, but still doesn't work: class (Monad i, Monad o) => MonadTrans' i o where lift' :: i a -> o a instance Monad m => MonadTrans' m m where lift' = id instance (MonadTrans t, MonadTrans' a b) => MonadTrans' a (t b) where lift' = lift . lift' -- Taral <taralx@gmail.com> "You can't prove anything." -- Gödel's Incompetence Theorem
On 3/13/07, Taral <taralx@gmail.com> wrote:
This is closer, but still doesn't work:
And this works, and I don't know why: class MonadTrans' i o where lift' :: (Monad i, Monad o) => i a -> o a instance Monad m => MonadTrans' m m where lift' = id instance (MonadTrans t, Monad b, MonadTrans' a b) => MonadTrans' a (t b) where lift' = lift . lift' Help? -- Taral <taralx@gmail.com> "You can't prove anything." -- Gödel's Incompetence Theorem
And this works, and I don't know why:
mostly because you have pushed more possible conflicts till later - you could also have added Monad b, Monad (t b) to the context for the second instance in your previous version; shifting the constraints from the class to the method delays the point at which they are checked (definition vs use). if the Monad instances are really missing when you try to use that method, it will be picked up later; also, there is a potential instance overlap, as the more eager Hugs will tell you for the definitions, while GHC will also report that later, only if it occurs in use. claus
class MonadTrans' i o where lift' :: (Monad i, Monad o) => i a -> o a
instance Monad m => MonadTrans' m m where lift' = id
instance (MonadTrans t, Monad b, MonadTrans' a b) => MonadTrans' a (t b) where lift' = lift . lift'
Help?
participants (2)
-
Claus Reinke -
Taral