Safe Haskell  SafeInferred 

Language  Haskell2010 
This is a helper module that enables the use of letbound variables in your Sexpression.
Synopsis
 discoverLetBindings :: (Monoid str, IsString str, Eq str, Eq a, Show a) => DiscoveryGuide a str > SExpr a > SExpr a
 data DiscoveryGuide a str = Guide {
 maxLetBinds :: Int > Int
 minExprSize :: Int
 allowRecursion :: Bool
 weighting :: SExpr a > Int > Int
 letMaker :: IsString str => str > a
 labelMaker :: (IsString str, Monoid str) => str > SExpr a > a
 extractStr :: IsString str => a > Maybe str
 nativeGuide :: (str > a) > (str > SExpr a > a) > DiscoveryGuide a str
 letExpand :: (Eq a, Show a, Eq str, IsString str) => (a > Maybe str) > SExpr a > SExpr a
Documentation
This module allows let bindings to be introduced into the SExpression syntax.
For example, instead of:
(concat (if (enabled x) (+ (width x) (width y)) (width y)) " meters")
this can be rewritten with let bindings:
(let ((wy (width y)) (wboth (+ (width x) wy)) (wide (if (enabled x) wboth wy)) ) (concat wide " meters"))
As Sexpressions grow larger, letbinding can help readability for
those expressions. This module provides the discoverLetBindings
function that will convert an Sexpression into one containing
letbound variables, and the inverse function letExpand
which will
expand letbound variables back into the expression.
id = letExpand . discoverLetBindings guide
The typical use is to add let bindings before serializing to disk, and then expand the bindings after reading from the disk but before passing to other processing; this process allows the application using the SExpressions to be unaware of the letbinding compression, although it does not obtain corresponding advantages of the reuse of letbound variables.
The discoverLetBindings
function can be called to automatically
assign let bindings based on a weighting algorithm of discovered
Sexpression phrases. The discovery is guided by parameters provided
by the caller in the DiscoveryGuide
; this guide also provides the
functions used to create the variables and the toplevel let statement
in the language of the current Sexpression.
The weighting
function of the DiscoveryGuide
can be used to assign
weights to various Sexpression phrases: the Sexpressions with the
highest weights will be letbound to variables (up to the
maxLetBinds
limit). A weighting value of 0 will cause the
subexpression to be ignored (never letbound) and a value equal to or
greater than 1000000 will *always* insert a letbinding, ignoring all
other limits.
discoverLetBindings :: (Monoid str, IsString str, Eq str, Eq a, Show a) => DiscoveryGuide a str > SExpr a > SExpr a Source #
Called to convert a plain Sexpression into one with letbound variables. The let bindings are "discovered" with the assistance of the guide.
data DiscoveryGuide a str Source #
This object provides guidance to the discoverLetBindings
function, establishing various parameters for the discovery
process.
Guide  

nativeGuide :: (str > a) > (str > SExpr a > a) > DiscoveryGuide a str Source #
Returns a default DiscoveryGuide
.
Expanding
letExpand :: (Eq a, Show a, Eq str, IsString str) => (a > Maybe str) > SExpr a > SExpr a Source #
The letExpand
function is passed an Sexpression that (may)
contain letbound variables and will return an equivalent
Sexpression that does not contain any let bindings, where let
bindings have been expanded into the expression.