Randomized templating language DSL https://github.com/vmchale/madlang#readme
|Latest on Hackage:||18.104.22.168|
This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.
Madlang DSL for generating random text
This is the Madlang DSL for generating text. You specify a template, and Madlang will create randomized text from the template.
Madlang is an interpreted language, written in Haskell. It runs from the command line, but also provides a Haskell library that can be integrated into other projects, compiled to a web app, or used as an EDSL.
There is also a vim plugin for syntax highlighting, available here.
It can be used for twitter bots (among other things) and provides human-readable syntax for generating text.
# Madlang is a declarative language. The most basic component is a function, viz. :define coinFlip 1.0 "heads" 1.0 "tails" :define die 1.0 "1" 1.0 "2" 1.0 "3" 1.0 "4" 1.0 "5" 1.0 "6" # Madlang also has categories, that is, a collection of functions that can be # bundled together :category gambling coinFlip die # :return declarations handle the actual output :return 0.7 gambling 0.3 gambling.to_upper # .to_upper is a modifier which make the whole string uppercase
There are two keywords in madlang you'll use most:
:return is the main string we'll be spitting back; there can be only one per file.
:define on the other hand can be used to make functions. These functions are combinations of templates, organizing pairs of weights and strings.
There is a Shakespearean insult generator demo available in
If you're on linux or mac, you can get up-to-date binaries via nix.
Download nix with
curl https://nixos.org/nix/install | sh
nix-env -i madlang will install the proper executables.
curl -sSL http://haskellstack.org | sh
stack install madlang --resolver nightly and you'll get the
madlang executable installed on your path. This may take a bit of time, as it will build all dependencies of
To use it, try
$ madlang run demo/shakespeare.mad
You can do
madlang --help if you want a couple other options for debugging.
Using the Haskell library
One function you might want to use is
runFile; it reads a file and generates randomized text:
λ:> runFile  "demo/shakespeare.mad" "Thou hasty-witted gleeking puttock!"
To use the library as an EDSL, there are two options: splicing in a file or using a quasi-quoter, viz.
demo :: IO T.Text demo = run $(madFile "demo/shakespeare.mad") demo :: IO T.Text demo = run [|madlang :define f 1.0 "heads" 1.0 "tails" :return 1.0 f|]
Haddock documentation of all library functionality is located here.