| Safe Haskell | None |
|---|
Data.HList.RecordPuns
Description
- pun :: QuasiQuoter
Documentation
>>>:set -XQuasiQuotes -XViewPatterns
patterns
>>>let y = Label :: Label "y">>>let x = Label :: Label "x">>>[pun| x y |] <- return (x .=. 3 .*. y .=. "hi" .*. emptyRecord)>>>print (x,y)(3,"hi")
expressions
Compare with the standard way to construct records above
>>>let x = 3; y = "hi">>>[pun|x y|]Record{x=3,y="hi"}
nesting
Nesting is supported. The idea is that variables inside
{ } are in another record. More concretely:
[pun| ab@{ a b } y z c{d} |]
as a pattern, it will bindings from an original record x,
if you interpret (.) as a left-associative field lookup (as it
is in other languages):
let ab = xab
a = x.ab.a
b = x.ab.b
y = x.y
z = x.z
-- c is not bound
d = x.c.d
as an expression, it creates a new record which needs the variables
ab a b y z d in-scope. ab needs to be a record, and if it has
fields called a or b they are overridden by the values of a and b
which are in scope.
See also examples/pun.hs.
requires the use of Data.HList.Label6 (ie. the label for foo is Label :: Label "foo")