Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tek/exon
Customizable Quasiquote Interpolation
https://github.com/tek/exon
haskell quasiquotes string-interpolation
Last synced: about 2 months ago
JSON representation
Customizable Quasiquote Interpolation
- Host: GitHub
- URL: https://github.com/tek/exon
- Owner: tek
- Created: 2021-07-03T21:44:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-06T21:54:09.000Z (2 months ago)
- Last Synced: 2024-11-06T22:35:17.682Z (2 months ago)
- Topics: haskell, quasiquotes, string-interpolation
- Language: Nix
- Homepage:
- Size: 157 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
This Haskell library provides string interpolation in quasiquotes, allowing you to build strings like this:
```haskell
animal = "snake"
location = "a tree"
[exon|#{animal} in #{location}|]
-- "snake in a tree"
```Please consult [hackage] for the full documentation.
Each step of the process is customizable based on the result type of the quote, making it possible to construct strings
for arbitrary types.
For example, `String -> String` is the type used by `showsPrec`, which can be a bit of a hassle to write:```haskell
data Record =
Record {
number :: Int,
maybeNumber :: Maybe Int,
value :: Value
}instance Show Record where
showsPrec d Record {..} =
showParen (d > 10) [exon|Record #{showsPrec 11 number} #{showsPrec 11 maybeNumber} #{showsPrec 11 value}|]
```[hackage]: https://hackage.haskell.org/package/exon/docs/Exon.html