Skip to content

Cannot use DefaultSignatures for TypeFamiles

I'm surprised there wasn't a ticket for this. Maybe I just couldn't find it.

In short, I want to do something like:

class Monad m => MyMonad m where
    type AssociatedMonad m :: Type -> Type
    default type AssociatedMonad m :: (m ~ t m', MonadTrans t, MyMonad m') => Type -> Type
    type AssociatedMonad (t m') = t (AssociatedMonad m')

    fun :: Foo -> m ()
    default fun :: (m ~ t m', MonadTrans t, MyMonad m') => Foo -> m ()
    fun = lift . fun

The syntax is a bit weird, but I hope in the process of implementing constrained type families the syntax properly analogous to the term-level would shake itself out.

The use-case, like the normal method original, is to assist with monad transformer boilerplate. MonadTrans wouldn't be enough, but MFunctor from mmorph might be depending on the method using the associated type.

Trac metadata
Trac field Value
Version 8.6.2
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