Stand-alone deriving declarations added

Manuel M T Chakravarty chak at cse.unsw.edu.au
Thu Oct 5 15:04:03 EDT 2006


Björn Bringert wrote:
> Bulat Ziganshin wrote:
> Stand-alone deriving declarations are actually a little bit weaker  
> than normal deriving clauses, since the current implementation does  
> not let you reference the type arguments of a newtype in the  
> arguments to the MPTC. This example from the GHC manual cannot  
> currently be done with stand-alone deriving:
> 
>    class StateMonad s m | m -> s where ...
>    instance Monad m => StateMonad s (State s m) where ...
> 
>    newtype Parser tok m a = Parser (State [tok] (Failure m) a)
>                           deriving (Monad, StateMonad [tok])
> 
> 
> The below does not work, since tok is not in scope:
> 
> deriving StateMonad [tok] for Parser
> 
> Maybe the syntax should be changed to be:
> 
> deriving (Class t1 ... tn) for Type a1 ... an
> 
> where a1 ... an are type variables. This would allow:
> 
> deriving StateMonad [tok] for Parser tok m a

I'd be much in favour of a story that make derivings at data/newtype
declarations simply syntactic sugar for a data/newtype declaration
without a deriving clause plus a couple of stand-alone deriving
declarations.

Manuel




More information about the Cvs-ghc mailing list