What is the type of a very simple unwrap function for a transformed monad?

151 views Asked by At

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.

1

There are 1 answers

0
Bakuriu On BEST ANSWER

Just look at the definition:

unET (ET m) = m

you know that the only field of ET has type: m (Maybe a). The unET function takes an ET m a and returns its only field, so the return type of unET must be the type of the field, i.e. m (Maybe a) and not m a!