-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Render numeric expressions to their textual representation. -- -- This library allows you to render a numeric expression to its textual -- representation. For example: -- --
--   *Repr> let rd = 1.5 + 2 + (3 + (-4) * (5 - pi / sqrt 6)) :: Repr Double
--   *Repr> render rd
--   "fromRational (3 % 2) + fromInteger 2 + (fromInteger 3 + negate (fromInteger 4) * (fromInteger 5 - pi / sqrt (fromInteger 6)))"
--   
@package repr @version 0.2 module Repr -- | Repr a is a value of type a paired with a way to -- render that value to a string which will contain a representation of -- the value. -- -- Note that Repr a is overloaded for all the numeric classes -- 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> value r
--   17.281195923884734
--   
-- -- And you can than render r to its textual representation: -- --
--   *Repr> render 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. value :: Repr a -> a -- | Extrac the renderer of the Repr. renderer :: Repr a -> Renderer -- | To render you need to supply the precedence and fixity of the -- enclosing context. -- -- (For rendering top-level values see render.) -- -- 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 a -- String for example, 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. -- -- type Precedence = Int -- | Fixity of operators. data Fixity -- | No fixity information. Non :: Fixity -- | Left associative operator. L :: Fixity -- | Right associative operator. R :: Fixity -- | Render a top-level value to a String. Note that: -- --
--   render r = toString $ renderer r 0 Non
--   
render :: Repr a -> String -- | 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 a -> DString -> Repr a instance Eq Fixity instance (IsString a) => IsString (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 Show (Repr a)