RepLib-0.5.4: Generic programming library with representation types

Safe HaskellNone
LanguageHaskell2010

Generics.RepLib.PreludeLib

Description

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.

Synopsis

Documentation

data EqD a Source #

Instances

Eq a => Sat (EqD a) Source # 

Methods

dict :: EqD a Source #

eqR1 :: R1 EqD a -> a -> a -> Bool Source #

Polymorphic equality, given an R1 representation

data OrdD a Source #

Instances

Ord a => Sat (OrdD a) Source # 

Methods

dict :: OrdD a Source #

compareR1 :: R1 OrdD a -> a -> a -> Ordering Source #

Minimal completion of the Ord class

data BoundedD a Source #

Instances

Bounded a => Sat (BoundedD a) Source # 

Methods

dict :: BoundedD a Source #

minBoundR1 :: R1 BoundedD a -> a Source #

To generate the Bounded class

maxBoundR1 :: R1 BoundedD a -> a Source #

To generate the Bounded class

data ShowD a Source #

Instances

Show a => Sat (ShowD a) Source # 

Methods

dict :: ShowD a Source #

showsPrecR1 :: R1 ShowD a -> Int -> a -> ShowS Source #

Minimal completion of the show class