subhask- Type safe interface for programming in subcategories of Hask

Safe HaskellNone




FIXME: doesn't handle multiparameter classes like Integral and Vector

FIXME: should this be separated out into another lib when finished?


template haskell functions

deriveHierarchy :: Name -> [Name] -> Q [Dec] Source

This is the main TH function to call when deriving classes for a newtype. You only need to list the final classes in the hierarchy that are supposed to be derived. All the intermediate classes will be derived automatically.

deriveHierarchyFiltered :: Name -> [Name] -> [Name] -> Q [Dec] Source

Like "deriveHierarchy" except classes in the second list will not be derived.

deriveSingleInstance :: Name -> Name -> Q [Dec] Source

Given a single newtype and single class, constructs newtype instances

deriveTypefamilies :: [Name] -> Name -> Q [Dec] Source

creates the instance:

type instance Scalar (Newtype s) = Scalar s

mkMutableNewtype :: Name -> Q [Dec] Source

Create a Mutable instance for newtype wrappers. The instance has the form:

newtype instance Mutable m (TyCon t) = Mutable_TyCon (Mutable m t)

Also create the appropriate IsMutable instance.

FIXME: Currently uses default implementations which are slow.

listSuperClasses :: Name -> Q [Name] Source

List all the superclasses of a one parameter class. This does not include: * constraints involving types other than the parameter (e.g. made with type families). * type synonyms (although these will get substituted in the recursion)

For example, convert ''Group into [''Semigroup, ''Monoid, ''Cancellative, ''Group]

compatibility functions

fromPreludeEq :: Q Type -> Q [Dec] Source

Generate an Eq_ instance from the Prelude's Eq instance. This requires that Logic t = Bool, so we also generate this type instance.


type BasicType t = (Show t, Read t, Arbitrary t, NFData t) Source

This class provides an artificial hierarchy that defines all the classes that a "well behaved" data type should implement. All newtypes will derive them automatically.

helper_liftM :: Monad m => (a -> b) -> m a -> m b Source

We need to export this function for deriving of Monadic functions to work

helper_id :: a -> a Source