The madlang package

[Tags:benchmark, bsd3, library, program, test]

Please see

[Skip to Readme]


Dependencies ansi-wl-pprint, base (>=4.7 && <5), containers, lens, madlang, megaparsec, mtl, mwc-random, optparse-applicative, text, tibetan-utils [details]
License BSD3
Copyright Copyright: (c) 2016 Vanessa McHale
Author Vanessa McHale
Stability experimental
Category Web
Home page
Source repository head: git clone
Uploaded Sun Mar 26 21:45:19 UTC 2017 by vmchale
Distributions NixOS:
Downloads 265 total (164 in the last 30 days)
0 []
Status Docs available [build log]
Last success reported on 2017-03-26 [all 1 reports]




llvm-fastEnable build with llvm backendDisabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for madlang

Readme for madlang-

Madlang DSL for generating random text

Build Status

This is the Madlang DSL for generating random text. There is also a vim plugin, available here.

It enables you to generate random templated text with very little effort or expertise.

It can be used for twitter bots and provides human-readable syntax for Markov chains often used in natural language processing.


An exmaple is worth a thousand words, so suppose you wanted to generate a mediocre fortune telling bot. You could write the following code:

:define person
    0.7 "A close friend will "
    0.3 "You will "
:define goodfortune
    0.2 person "make rain on the planet Mars"
    0.8 "nice things will happen today :)"
:define fortune
    0.5 "drink a boatload of milk"
    0.5 "get angry for no reason"
    0.8 person fortune
    0.2 goodfortune

There are two "statements" in madlang, :define and :return. :return is the main string we'll be spitting back, so there can be only one per file. :define on the other hand can be used to make multiple templates. These templates are combinations of strings (enclosed in quotes) and names of other templates.

Of course, you can't have a circular reference with names - if goodfortune depends on fortune while fortune depends on goodfortune, we end up with either no fortune or an infinite fortune. So we throw an error.

Using the libary

The main function you'll want to use is probably runFile; it reads a file and generates randomized text:

 λ:> runFile [] "test/templates/gambling.mad"

Haddock documentation of all available functionality is located here.



If you're on windows or linux, grabbing release binaries is probably the easiest. Find them here.


Download stack with

curl -sSL | sh

Then run stack install madlang --resolver nightly and you'll get the madlang executable installed on your path.

You can also run stack install in the appropriate directory after cloning this repository.


To use it, try

 $ madlang run fortune-teller.mad

You can do madlang --help if you want a couple other options for debugging.

Syntax Highlighting

Syntax highlighting for the DSL is provided in the vim plugin here. It includes integration with syntastic.