Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Expression
- type Str'Static = Text
- newtype Str'Dynamic = Str'Dynamic {}
- data Str'1
- strDynamic'toList :: Str'Dynamic -> [Str'1]
- strDynamic'fromList :: [Str'1] -> Str'Dynamic
- strDynamic'singleton :: Str'1 -> Str'Dynamic
- str'dynamicToStatic :: Str'Dynamic -> Maybe Str'Static
- str'staticToDynamic :: Str'Static -> Str'Dynamic
- str'unquotedToDynamic :: Str'Unquoted -> Str'Dynamic
- newtype List = List (Seq Expression)
- data Dict = Dict {}
- data DictBinding
- data Dot = Dot {}
- expression'applyDots :: Expression -> [Expression] -> Expression
- data Lambda = Lambda {}
- data Param
- data DictPattern = DictPattern {}
- data DictPattern'1 = DictPattern'1 {}
- data Apply = Apply {}
- expression'applyArgs :: Expression -> [Expression] -> Expression
- data Let = Let {}
- data LetBinding
- data With = With {}
- data Inherit = Inherit {}
Expressions
data Expression Source #
Expr'Var Str'Unquoted | A variable, such as |
Expr'Str Str'Dynamic | A string may be quoted either in the traditional form using a
single double-quote ( "one\ntwo" or in the "indented string" form using two single-quotes ( '' one two '' Both of these examples reduce to the same value, because leading whitespace is stripped from indented strings. Either may contain "antiquotation" (also known as "string interpolation") to conveniently concatenate string-valued variables into the string. "Hello, my name is ${name}!" Normal strings may contain the following escape sequences:
The indented string form does not interpret any escape sequences. |
Expr'List List | A list is an ordered collection of expressions. The empty list: [ ] A list containing three variables: [ a b c ] Lambdas, function applications, [ (x: f x y) (g y) (let a = y; in f a a) (with d; f x a) ] |
Expr'Dict Dict | A dict is an unordered extensional mapping from strings. The empty dict (with no bindings): { } A dict with two bindings: { a = "one"; b = "one two"; } By default, dict bindings cannot refer to each other. For that, you
need the rec { a = "one"; b = "${a} two"; } In either case, the order of the bindings does not matter. The left-hand side of a dict binding may be a quoted string (in the
traditional { "a b" = "c"; } The left-hand side of a dict may even be an arbitrary expression,
using the let x = "a b"; in { ${x} = "c"; } Dicts also support the { inherit a; inherit (x) c d; } The previous expression is equivalent to: { a = a; c = x.c; d = x.d; } |
Expr'Dot Dot | A dot expression (named after the The examples in this section all reduce to Z. { a = "Z"; }.a let x = { a = "Z"; }; in x.a { x = { a = "Z"; }; }.x.a The right-hand side of a dot may be a quoted string (in the
traditional { a = "Z"; }."a" The right-hand side of a dot may even be an arbitrary expression,
using the { a = "Z"; }.${ let b = "a"; in b } |
Expr'Lambda Lambda | A lambda expression This is a function that turns a name into a greeting: name: "Hello, ${name}!" The function parameter can also be a dict pattern, which looks like this: { a, b, c ? "another" }: "Hello, ${a}, ${b}, and ${c}!" That function accepts a dict and looks up the keys By default, a lambda defined with a dict pattern fails to evaluate if
the dict argument contains keys that are not listed in the pattern.
To prevent it from failing, you can end the pattern with ({ a, ... }: x) { a = "1"; b = "2"; } Every function has a single parameter. If you need multiple parameters, you have to curry: a: b: [ a b ] |
Expr'Apply Apply | Function application: f x If a function has multiple (curried) parameters, you can chain them together like so: f x y z |
Expr'Let Let | A let-in expression: let greet = x: "Hello, ${x}!"; name = "Chris"; in greet name Let bindings, like dict bindings, may also use the let d = { greet = x: "Hello, ${x}!"; name = "Chris"; } inherit (d) greet name; in greet name The previous example also demonstrates how the bindings in a let
expression may refer to each other (much like a dict with the |
Expr'With With | A with expression is similar to a let-in expression, but the bindings come from a dict. with { greet = x: "Hello, ${x}!"; name = "Chris"; }; greet name |
Show Expression Source # | This instance is designed for doctests and REPL experimentation. The
format is designed to strike a balance in verbosity between the derived |
Binding Expression DictBinding Source # | |
Strings
type Str'Static = Text Source #
A fixed string value. We use the description "static" to mean the string
may not contain antiquotation, in contrast with Str'Dynamic
which can.
newtype Str'Dynamic Source #
A quoted string expression, which may be a simple string like "hello"
or
a more complex string containing antiquotation like "Hello, my name is
${name}!"
. See Expr'Str
.
We use the description "dynamic" to mean the string may contain antiquotation,
in contrast with Str'Static
which cannot.
One part of a Str'Dynamic
.
strDynamic'toList :: Str'Dynamic -> [Str'1] Source #
strDynamic'fromList :: [Str'1] -> Str'Dynamic Source #
String conversions
Lists
A list literal expression, starting with [
and ending with ]
.
See Expr'List
.
Dicts
A dict literal expression, starting with {
or rec {
and ending with
}
. See Expr'Dict
.
Dict | |
|
data DictBinding Source #
A binding of the form x = y;
within a DictLiteral
or LetExpr
.
Dict lookup
An expression of the form person.name
that looks up a key from a dict.
See Expr'Dot
.
Dot | |
|
:: Expression | Dict |
-> [Expression] | Lookups |
-> Expression | Dot expression |
Lambdas
A function expression. See Expr'Lambda
.
Lambda | |
|
Function parameters
A parameter to a Lambda
. All functions have a single parameter, but it's
more complicated than that because it may also include dict destructuring.
Param'Name Str'Unquoted | A simple single-parameter function |
Param'DictPattern DictPattern | Dict destructuring, which gives you something resembling multiple named parameters with default values |
Param'Both Str'Unquoted DictPattern | Both a param name and a dict pattern, separated by the |
data DictPattern Source #
A type of function parameter (Param
) that does dict destructuring.
DictPattern | |
|
data DictPattern'1 Source #
One item within a DictPattern
.
DictPattern'1 | |
|
Function application
A function application expression. See Expr'Apply
.
Apply | |
|
:: Expression | Function |
-> [Expression] | Args |
-> Expression | Function application |
let
A let
-in
expression. See Expr'Let
.
Let | |
|
data LetBinding Source #
A semicolon-terminated binding within the binding list of a Let
expression.
LetBinding'Eq Str'Static Expression | A binding with an equals sign, of the form |
LetBinding'Inherit Inherit | A binding using the |
with
A with
expression. See Expr'With
.