Copyright | (c) songzh |
---|---|
License | BSD3 |
Maintainer | Haskell.Zhang.Song@hotmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Class dependencies can be complex sometimes, such as numeric and monadic classes. Making instances of them can be very tedious. Functoins in this module will help you derive the specified class instance with all the superclass instances of it. For using this module, you may need to enable the following langauge extensions: TemplateHaskell
, StandaloneDeriving
, DeriveGeneric
, DeriveDataTypeable
, GeneralizedNewtypeDeriving
, DeriveAnyClass
You may also need to enable GHC options -ddump-splices
.
For example:
data A = A deriving_superclasses ''Ord ''A
You wil get:
deriving_superclasses ''Ord ''A ======> deriving instance Ord A deriving instance Eq A
Eq
is automatically derived when Ord
is derived, since Eq
is a superclass of Ord
newtype IO_ a = IO_ (IO a) strategy_deriving_superclasses newtype_ ''MonadIO ''IO_
You will get:
strategy_deriving_superclasses newtype_ ''MonadIO ''IO_ ======> deriving newtype instance MonadIO IO_ deriving newtype instance Monad IO_ deriving newtype instance Applicative IO_ deriving newtype instance Functor IO_
Appearently, Functor f => Applicative f => Monad f => MonadIO f
newtype F32 = F32 Float newtype_deriving_superclasses ''RealFloat ''F32
You will get:
newtype_deriving_superclasses ''RealFloat ''F32 ======> deriving newtype instance RealFloat F32 deriving newtype instance RealFrac F32 deriving newtype instance Real F32 deriving newtype instance Num F32 deriving newtype instance Ord F32 deriving newtype instance Eq F32 deriving newtype instance Fractional F32 deriving newtype instance Floating F32
Some of these examples are from #13368.
Documentation
strategy_deriving_superclasses :: DerivStrategy -> Name -> Name -> Q [Dec] Source #