Skip to content

Flexible and extensible interpolation for Haskell

License

Notifications You must be signed in to change notification settings

serokell/nyan-interpolation

Repository files navigation

Nyan-interpolation

License: MPL 2.0 GitHub CI

nyan-interpolation nyan-interpolation-core nyan-interpolation-simple

Flexible production-scale string interpolation library.

Motivation

We wanted a solution that would

  • Use efficient Buildable and FromBuildable by default, but would allow using Show if necessary too.
  • Have numerious switches: indentation stripping, spaces trimming, result preview, and more.
  • Have two variations:
    • Full-fledged interpolator, but with a heavy haskell-src-exts dependency;
    • Light-weight interpolator that interpolates only variables, but not arbitrary expressions.
  • Have convenient defaults, that both can be overriden at use site and customized in the quasi-quoter.
    • It is still possible to use Show as default;
    • Default set of switches can be changed to suit your preferences.

How To Use

The usage looks like:

import Text.Interpolation.Nyan

myText :: Text
myText =
  let val = 5 :: Int
  [int|s| Value is #{val} |]
-- "Value is 5"

myMultilineText :: Text
myMultilineText =
  [int||
    What would you get if you fix a cat and a rainbow?
    And a cookie?
  |]
-- "What would you get if you fix a cat and a rainbow?\nAnd a cockie?\n"

The full introduction can be found in the haddock documentation.

Packages

This repository contains the following haskell packages:

IDE Integration

VSCode

We provide snippets, and syntax highlighting is yet to be implemented (see #3).

For Contributors

Please see CONTRIBUTING.md for more information.

About Serokell

Nyan-interpolation is maintained and funded with ❤️ by Serokell. The names and logo for Serokell are trademark of Serokell OÜ.

We love open source software! See our other projects or hire us to design, develop and grow your idea!