Opened 3 years ago

Last modified 2 years ago

#12639 new feature request

Inconsistent treatment of FlexibleInstances and MPTCs with standard vs. flexible deriving

Reported by: dfeuer Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 8.1
Keywords: deriving Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Given {-# LANGUAGE GeneralizedNewtypeDeriving #-}, I can write

import Control.Monad.State.Strict

newtype Foo s m a = Foo (StateT s m a)
  deriving (Functor, Applicative, Monad, MonadState s)

However, if I want to use StandaloneDeriving to make the MonadState instance more explicit,

deriving instance Monad m => MonadState s (Foo s m)

I suddenly need to add FlexibleInstances and MultiParamTypeClasses.

In my personal opinion, the most sensible way to handle this is to change two things in two different directions:

  1. Allow MPTC instance declarations (but not class declarations) without MultiParamTypeClasses.
  1. Require FlexibleInstances for standard deriving clauses when they would be required for standalone deriving declarations.

Change History (2)

comment:1 Changed 3 years ago by RyanGlScott

I have some opinions on both of these suggestions, but I'll refrain from posting them here. Before that, if you really want to see these changes make it into GHC, you should propose them as a post to the GHC devs mailing list. In particular, your second proposed item would cause a lot of code in the wild to break, so we need to discuss it more thoroughly to ensure it's a breakage we want to endorse.

comment:2 Changed 2 years ago by RyanGlScott

Keywords: deriving added
Note: See TracTickets for help on using tickets.