intrinsic-superclasses-0.3.0.0: A quasiquoter for better instance deriving and default methods

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.Instances.Internal

Synopsis

Documentation

instances :: QuasiQuoter Source #

QuasiQuoter for providing intrinsic-superclasses.

Example:

 class Semigroup a where mappend :: a -> a -> a
 class Semigroup a => Commutative a
 class Semigroup a => Monoid a where mempty :: a
 class Monoid a => Group a where inverse :: a -> a
 class (Commutative a, Group a) => CommutativeGroup a
 [instances| Num a => CommutativeGroup a where
     mempty = fromInteger 0
     mappend a b = a + b
     inverse = negate
     |]

will generate the appropriate instances for Semigroup, Monoid, and Group:

 instance Num a => Semigroup a where mappend a b = a + b
 instance Num a => Commutative a
 instance Num a => Monoid a where mempty = fromInteger 0
 instance Num a => Group a where inverse = negate
 instance Num a => CommutativeGroup a

splitInstances :: Dec -> DecsQ Source #

Implements the instances quasiquoter ast transform

globalizeClass :: Name -> Q Name Source #

Get the fully qualified name of a class

getClassOps :: Traversable t => t Dec -> Map ParentName (Set Name) -> Q (Map ParentName (Set Name)) Source #

Create a Map of className to method declaration from a list of instance method definitions

defName :: Dec -> Name Source #

Get the name of a function or value declaration

getSuperclassNames :: Name -> Q [Name] Source #

reify the names of the direct superclasses for a class name

getTransitiveSuperclassNames :: Name -> Q (Map Name (Set a)) Source #

reify the names of all transitive superclasses for a class name, including itself

occName :: Name -> String Source #

Extract the unqualified part from a Name. For example:

show ''Show === "GHC.Show.Show"
occName ''Show === "Show"