test-fun-0.1.0.0: Testable functions

Safe HaskellSafe
LanguageHaskell2010

Test.Fun.Internal.Pretty

Contents

Description

Pretty printing of function representations.

Warning

This is an internal module: it is not subject to any versioning policy, breaking changes can happen at any time. It is made available only for debugging. Otherwise, use Test.Fun.

If something here seems useful, please open an issue to export it from an external module.

Synopsis

Interface

showsPrecFun :: forall a r. ShowsPrec r -> ShowsPrec (a :-> r) Source #

Prettify function representation.

indent :: String -> String Source #

Break up lines after braces and indent.

Example

Expand

Input:

\x -> case x :: Either _ _ of { Left x1 -> case x1 of { Left x2 -> () ; Right x2 -> case x2 of {} } ; Right x1 -> () }

Output:

\x -> case x :: Either _ _ of {
  Left x1 -> case x1 of {
    Left x2 -> () ;
    Right x2 -> case x2 of {} } ;
  Right x1 -> () }

prettyFun :: forall a r. (r -> C Expr) -> (a :-> r) -> String Source #

Implementation

Strings

(%) :: DString -> DString -> DString infixr 1 Source #

(~%) :: String -> DString -> DString infixr 1 Source #

Pretty-printed expressions

newtype Expr Source #

Constructors

Expr 

Fields

data Var Source #

Constructors

Var String !Int 

data Ctx Source #

Constructors

(Var, Expr) :. Ctx infixr 1 

type C a = Ctx -> a Source #

Type of values under some context

Basic expression constructors

tShow :: Show a => a -> C Expr Source #

tShow_ :: ShowsPrec a -> a -> C Expr Source #

addVar :: [Var] -> Ctx -> Ctx Source #

Main implementation

tFun :: forall a r. (r -> C Expr) -> (a :-> r) -> C Expr Source #

Pretty-print a function representation.

tCoApply :: Concrete w -> w -> C Expr -> C Expr Source #

appendIf :: Semigroup m => Bool -> m -> m -> m Source #

partialBranches :: Branches x r -> Bool Source #

True if there is a Fail branch.

tBranches :: forall x r. (r -> C Expr) -> Branches x r -> CBranches Source #

tFields :: forall x r. (r -> C Expr) -> Fields x r -> ConName -> [Var] -> CBranches Source #

tBin :: (r -> C Expr) -> Bin r -> CBranches Source #

data Sign Source #

Constructors

Pos 
Neg 

tBin' :: (r -> C Expr) -> Bin r -> C [(Integer, Expr)] Source #