Any way to set up one or two methods of instances of GeneralizedNewtypeDeriving?

Haskell GeneralizedNewtypeDeriving mechanism is great; for those who did not see it by writing something like

newtype SkewOptT 𝔪 α = SkewOptT (StateT Bool 𝔪 α) deriving (Applicative, Functor, Monad, MonadTrans) 

automatically generates instances such as

 instance [overlap ok] Monad 𝔪 => Monad (SkewOptT 𝔪) 

However, for one of my classes, I want to set up several methods. Is there a way to override or disable what GeneralizedNewtypeDeriving does for these methods? The typeclass class encodes some basic DSL instructions, such as for (loop), parfor (parallel loop), fcndef (add a new function), etc., And there is no ideal way to break it up into several types of styles [and then automatically output one and manually record another].

+4
source share
1 answer

No, It is Immpossible. Default signatures (new in GHC 7.2) can help you split classes here; since you can define default implementations for methods in terms of other types, you can get some instances and just populate the methods you want to override in an instance of another class.

In fact, besides Show and Read , newtype only displays checks that several preconditions are fulfilled, and then reuses the dictionary directly (since newtypes have the same representation as the base type); see the documentation for more details.

+4
source

Source: https://habr.com/ru/post/1388843/


All Articles