-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Render overloaded expressions to their textual representation. -- -- This library allows you to render overloaded expressions to their -- textual representation. For example: -- --
--   *Repr> let rd = 1.5 + 2 + (3 + (-4) * (5 - pi / sqrt 6)) :: Repr Double
--   *Repr> show rd
--   "fromRational (3 % 2) + 2 + (3 + negate 4 * (5 - pi / sqrt 6))"
--   
@package repr @version 0.4 module Text.Repr -- | Repr α is a value of type α paired with a way to -- render that value to its textual representation. -- -- Reprs follow the property that given a Repr -- r if you evaluate the textual representation of r -- you should get the value or r. -- -- Note that Repr α has an instance for most classes in -- base provided that α has instances for the respected -- classes. This allows you to write a numeric expression of type -- Repr α. For example: -- --
--   *Repr> let r = 1.5 + 2 + (3 + (-4) * (5 - pi / sqrt 6)) :: Repr Double
--   
-- -- You can extract the value of r: -- --
--   *Repr> extract r
--   17.281195923884734
--   
-- -- And you can render r to its textual representation using -- show: -- --
--   *Repr> show r
--   "fromRational (3 % 2) + 2 + (3 + negate 4 * (5 - pi / sqrt 6))"
--   
data Repr α -- | Construct a Repr from the given value and its renderer. repr :: α -> Renderer -> Repr α -- | Extract the value of the Repr. extract :: Repr α -> α -- | Extract the renderer of the Repr. renderer :: Repr α -> Renderer -- | To render you need to supply the precedence and fixity of the -- enclosing context. -- -- For more documentation about precedence and fixity see: -- -- http://haskell.org/onlinereport/decls.html#sect4.4.2 -- -- The reason the renderer returns a DString, instead of for -- example a String has to do with efficiency. The rendering of -- expressions involves lots of left-factored appends i.e.: ((a ++ b) -- ++ c) ++ d. A DString, which is equivalent to a -- ShowS, has a O(1) append operation while a String -- has a O(n) append. type Renderer = Precedence -> Fixity -> DString -- | The precedence of operators and function application. -- -- type Precedence = Int -- | Fixity of operators. data Fixity -- | No fixity information. Non :: Fixity -- | Left associative operator. L :: Fixity -- | Right associative operator. R :: Fixity -- | x <?> s annotates the rendering with the given string. -- -- The rendering wil look like: "({- s -} ...)" where -- ... is the rendering of x. -- -- This combinator is handy when you want to render the ouput of a -- function and you want to see how the parameters of the function -- contribute to the result. For example, suppose you defined the -- following function f: -- --
--   f p0 p1 p2 = p0 ^ 2 + sqrt p1 * ([p2..] !! 10)
--   
-- -- You can then apply f to some parameters annotated with some -- descriptive strings (the name of the parameter is usally a good idea): -- --
--   f (1 <?> "p0") (2 <?> "p1") (3 <?> "p2")
--   
-- -- The rendering will then look like: -- --
--   "({- p0 -} fromInteger 1) * ({- p0 -} fromInteger 1) + sqrt ({- p1 -} (fromInteger 2)) * enumFrom ({- p2 -} (fromInteger 3)) !! 10"
--   
() :: Repr α -> DString -> Repr α -- | pure x constructs a Repr which has x as value -- and the showed x as rendering. For example: -- --
--   *Repr> let r = pure [1,2,3]
--   *Repr> extract r
--   [1,2,3]
--   *Repr> show r
--   "[1,2,3]"
--   
pure :: Show α => α -> Repr α instance Typeable1 Repr instance Eq Fixity instance (Random α, Show α) => Random (Repr α) instance Exception α => Exception (Repr α) instance (Show α, Storable α) => Storable (Repr α) instance Ix α => Ix (Repr α) instance HasResolution α => HasResolution (Repr α) instance Bits α => Bits (Repr α) instance Monoid α => Monoid (Repr α) instance Bounded α => Bounded (Repr α) instance Eq α => Eq (Repr α) instance Ord α => Ord (Repr α) instance Enum α => Enum (Repr α) instance RealFloat α => RealFloat (Repr α) instance RealFrac α => RealFrac (Repr α) instance Floating α => Floating (Repr α) instance Fractional α => Fractional (Repr α) instance Integral α => Integral (Repr α) instance Real α => Real (Repr α) instance Num α => Num (Repr α) instance IsString α => IsString (Repr α) instance Read α => Read (Repr α) instance Show (Repr α)