Reputation: 16850
Haskell's GeneralizedNewtypeDeriving mechanism is great; for those who haven't seen it, writing something like
newtype SkewOptT 𝔪 α = SkewOptT (StateT Bool 𝔪 α)
deriving (Applicative, Functor, Monad, MonadTrans)
will automatically generate instances like,
instance [overlap ok] Monad 𝔪 => Monad (SkewOptT 𝔪)
However, for one of my typeclasses, I want to customize a few methods. Is there a way to override, or disable what GeneralizedNewtypeDeriving does for these methods? The typeclass encodes some basic DSL instructions, like for
(a loop), parfor
(a parallel loop), fcndef
(add a new function), etc., and there isn't a perfect way to split it up into multiple typeclasses [and then automatically derive one, and manually write the other].
Upvotes: 4
Views: 333
Reputation: 40787
No, this is not possible. Default signatures (new in GHC 7.2) might help you split up the classes here, though; since you can define default implementations of methods in terms of other typeclasses, you might be able to derive some instances and only fill in the methods you want to override in the instance of another class.
In fact, apart from Show
and Read
, newtype deriving just checks that a few preconditions are met, and then reuses the dictionary directly (since newtypes have the same representation as the underlying type); see the documentation for more detail.
Upvotes: 4