Skip to content

Type synonyms with hidden, determined type variables

I found myself wanting to write (simplified)

type MyMonad m = (MonadReader r m, Show r)

but GHC does not accept this, it wants r as part of the type synonym. So why did I think this could work? Because MonadReader has a functional dependency:

class Monad m => MonadReader r m | m -> r

so if m determines r, why do I have to write MyMonad r m and not just MyMonad m? Can I not “hide” the fact that, somewhere internal to the MyMonad synonym, there is an additional variable r around?

Clearly supporting this would need a language proposal, but I wanted to open a ticket here first to hear if this would even be possible to implement.

(Others have wanted this before as well.)

Trac metadata
Trac field Value
Version 8.5
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information