Safe Haskell | None |
---|---|
Language | Haskell2010 |
- record :: QuasiQuoter
- lens :: QuasiQuoter
- r :: QuasiQuoter
- l :: QuasiQuoter
Documentation
A quasiquoter, which generates record expressions and types, depending on the context it's used in.
Here is how you can use it to declare types:
type Person = [record| {name :: String, birthday :: {year :: Int, month :: Int, day :: Int}} |]
To declare functions:
getAge :: [record| {name :: String, age :: Int} |] -> Int
To declare values:
person :: Person person = [record| {name = "Grigori Yakovlevich Perelman", birthday = {year = 1966, month = 6, day = 13}} |]
A quasiquoter, which generates a Lens
.
Lens is your interface to accessing and modifying the fields of a record.
Here is how you can use it:
getPersonBirthdayYear :: Person -> Int getPersonBirthdayYear = Record.Lens.view ([lens|birthday|] . [lens|year|])
For your convenience you can compose lenses from inside of the quotation:
setPersonBirthdayYear :: Int -> Person -> Person setPersonBirthdayYear = Record.Lens.set [lens|birthday.year|]
You can also use this function to manipulate tuples of arity up to 24:
mapThirdElement :: (Char -> Char) -> (Int, String, Char) -> (Int, String, Char) mapThirdElement = Record.Lens.over [lens|3|]
Shorthands
r :: QuasiQuoter Source
A shorthand alias to record
.
l :: QuasiQuoter Source
A shorthand alias to lens
.