madlang: Randomized templating language DSL

[ bsd3, library, text ] [ Propose Tags ]

Please see

[Skip to Readme]
Versions [faq],,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Dependencies ansi-wl-pprint (>= && <0.7), base (>= && <4.10), gitrev (>=1.2.0 && <1.3), lens (>=4.15.1 && <4.16), madlang (>= && <1.1), megaparsec (>=5.2.0 && <5.3), mtl (>=2.2.1 && <2.3), mwc-random (>= && <0.14), optparse-generic (>=1.1.4 && <1.2), text (>= && <1.3) [details]
License BSD-3-Clause
Copyright Copyright: (c) 2016 Vanessa McHale
Author Vanessa McHale
Category Web
Home page
Source repo head: git clone
Uploaded by vmchale at Fri Feb 24 23:22:25 UTC 2017
Distributions NixOS:
Executables madlang
Downloads 24557 total (849 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
All reported builds failed as of 2017-02-24 [all 3 reports]


  • Text
    • Text.Madlibs


Maintainer's Corner

For package maintainers and hackage trustees

Readme for madlang-

[back to package description]

Madlibs DSL for generating random text

This is the Madlibs DSL for generating random text. There is also a vim plugin for highlighting .mad files.

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

It can be used for twitter bots and more productive things.


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 you're only allowed one of them per file. :define on the other hand can be used to make as many templates as you want. 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, you'll end up with either no fortune or an infinite fortune. So instead we just 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.



Download stack with

curl -sSL | sh

Then run stack install and you'll get the madlang executable installed on your path. You can even do stack install madlang if you'd like.


To use it, just try

 $ madlang --input 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. You'll have to do :set syntax=madlang the first time you run it but everything else should work out of the box.: