I am exercising with monad transformers as presented in http://www.cs.nott.ac.uk/~nhn/MGS2006/LectureNotes/lecture03-9up.pdf
I have an implementation for an error transformer which reads like:
newtype ET m a = ET (m (Maybe a))
deriving instance Show (m (Maybe a)) => Show (ET m a)
(Actually this looks to me like MaybeT
, but ok...)
I wish to specify a function to unwrap ET
's. This function is given in the paper and does its job even without type declaration:
unET (ET m) = m
The thing is that I am uncapable to specify its type explicity. If I prepend a type which seems reasonable to me:
unET :: (Monad m) => ET m a -> m a
the error message is Could not deduce (a ~ Maybe a) from the context (Monad m)
What is the type of the unET
function?
I have already tried the magic compiler spells NoMonomorphismRestriction
, MonoLocalBinds
, which I've found in answers to similar questions. Still no joy.
Thank you for your attention.
Just look at the definition:
you know that the only field of
ET
has type:m (Maybe a)
. TheunET
function takes anET m a
and returns its only field, so the return type ofunET
must be the type of the field, i.e.m (Maybe a)
and notm a
!