madlang: Randomized templating language DSL

[ bsd3, library, web ] [ Propose Tags ]
Dependencies ansi‑wl‑pprint, base (>=4.7 && <5), composition, containers, directory, file‑embed, madlang, megaparsec, microlens, MonadRandom, mtl, optparse‑applicative, random‑shuffle, template‑haskell, text [details]
License BSD-3-Clause
Copyright Copyright: (c) 2016-2017 Vanessa McHale
Author Vanessa McHale
Category Web
Home page
Source repo head: darcs get
Uploaded by vmchale at Mon Jun 19 01:29:31 UTC 2017
Distributions NixOS:
Executables madlang
Downloads 13314 total (295 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-06-19 [all 1 reports]
Hackage Matrix CI

Please see

[Skip to Readme]





Enable build with llvm backend (produces a faster executable)


Don't build an executable


Enable the gold linker for faster build times


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-

[back to package description]

Madlang DSL for generating random text

Build Status

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.


An example 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"
:define intense
    1.0 person "wrestle in the WWE".to_upper
    1.0 person "bite in a bottle of hot sauce".to_upper
    0.7 person fortune
    0.1 intense
    0.2 goodfortune


There are two keywords in madlang you'll use most: :define and :return. :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 demo/shakespeare.mad



If you're on windows or linux, grabbing release binaries simplest. Find them here.


If you're on linux or mac, you can get up-to-date binaries via nix.

Download nix with

curl | sh

From there, nix-env -i madlang will install the proper executables.


Download stack with

curl -sSL | sh

Then run 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 madlang first.


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 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"
    1.0 f|]

Haddock documentation of all library functionality is located here.

Syntax Highlighting

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