RepLib- Generic programming library with representation types

Safe HaskellNone



The module PreludeLib contains generic operations to derive members of the standard prelude classess: Eq, Bounded, Compare, Show (TODO: add Enum and Read)

Although these classes may already be automatically derived via the deriving mechanism, this module is included for two reasons:

  • Deriving only works when datatypes are defined. This library allows instances of these classes to be generated anywhere. For example, suppose some other module contains the definition of the datatype T and exposes all of its constructors, but, frustratingly, does not derive an instance of the Show class.

You could define a Show instance of T in your own module with the following code:

 import RepLib

 (repr1 ''T)  -- make the Rep1 instance of T available

 instance Show T where
   showsPrec = showsPrecR1 rep1   -- showsPrecR1 is defined in this module
  • This library also serves as a model for generic functions that are slight modifications to these prelude operations. For example, if you wanted to define reverse lexicographic ordering or an XML pretty printer for datatypes, you might start here. This library is also a good place to start learning how to define your own generic operations, because the behavior of these operations should match the deriving mechanism specified by Haskell 98.



data EqD a Source


Eq a => Sat (EqD a) 

eqR1 :: R1 EqD a -> a -> a -> BoolSource

Polymorphic equality, given an R1 representation

data OrdD a Source


Ord a => Sat (OrdD a) 

compareR1 :: R1 OrdD a -> a -> a -> OrderingSource

Minimal completion of the Ord class

data BoundedD a Source


Bounded a => Sat (BoundedD a) 

minBoundR1 :: R1 BoundedD a -> aSource

To generate the Bounded class

maxBoundR1 :: R1 BoundedD a -> aSource

To generate the Bounded class

data ShowD a Source


Show a => Sat (ShowD a) 

showsPrecR1 :: R1 ShowD a -> Int -> a -> ShowSSource

Minimal completion of the show class