-- 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) + fromInteger 2 + (fromInteger 3 + negate (fromInteger 4) * (fromInteger 5 - pi / sqrt (fromInteger 6)))" --@package repr @version 0.3 module Text.Repr -- | Repr a is a value of type a paired with a way to -- render that value to its textual representation. -- -- Note that Repr a has an instance for most classes in base -- provided that a has instances for the respected classes. This -- allows you to write a numeric expression of type Repr a. 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) + fromInteger 2 + (fromInteger 3 + negate (fromInteger 4) * (fromInteger 5 - pi / sqrt (fromInteger 6)))" --data Repr a -- | Extract the value of the Repr. extract :: Repr a -> a -- | Extract the renderer of the Repr. renderer :: Repr a -> 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, is that the rendering of numeric expression -- involves lots of left-factored appends i.e.: ((a ++ b) ++ c) ++ -- d. A DString has a O(1) append operation while a -- String just has a O(n) append. So choosing a DString is -- more efficient. type Renderer = Precedence -> Fixity -> DString -- | The precedence of operators and function application. -- --
-- 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 a -> DString -> Repr a
-- | 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 a) => a -> Repr a instance Eq Fixity instance (Random a, Show a) => Random (Repr a) instance (Ix a) => Ix (Repr a) instance (HasResolution a) => HasResolution (Repr a) instance (Bits a) => Bits (Repr a) instance (Monoid a) => Monoid (Repr a) instance (Bounded a) => Bounded (Repr a) instance (Eq a) => Eq (Repr a) instance (Ord a) => Ord (Repr a) instance (Enum a) => Enum (Repr a) instance (RealFloat a) => RealFloat (Repr a) instance (RealFrac a) => RealFrac (Repr a) instance (Floating a) => Floating (Repr a) instance (Fractional a) => Fractional (Repr a) instance (Integral a) => Integral (Repr a) instance (Real a) => Real (Repr a) instance (Num a) => Num (Repr a) instance (ToString a) => ToString (Repr a) instance (IsString a) => IsString (Repr a) instance (Read a) => Read (Repr a) instance Show (Repr a)