madlang: Randomized templating language DSL

[ bsd3, library, text ] [ Propose Tags ]

Madlang is a text templating language written in Haskell, meant to explore computational creativity and generative literature.

[Skip to Readme]
Versions [faq],,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Dependencies ansi-wl-pprint, base (>=4.8 && <4.11), composition-prelude (>= && <, containers, directory, file-embed, http-client, http-client-tls, madlang, megaparsec (>=6.0 && <7.0), MonadRandom, mtl, optparse-applicative, random-shuffle, recursion-schemes, tar, template-haskell, text, th-lift-instances, titlecase (>=1.0), zip-archive, zlib [details]
License BSD-3-Clause
Copyright Copyright: (c) 2016-2017 Vanessa McHale
Author Vanessa McHale
Revised Revision 2 made by vmchale at Tue Sep 4 23:12:03 UTC 2018
Category Web
Home page
Source repo head: darcs get
Uploaded by vmchale at Thu Oct 26 15:19:50 UTC 2017
Distributions NixOS:
Executables madlang
Downloads 24456 total (749 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2017-10-26 [all 1 reports]





Turn on -Werror


Enable build with llvm backend (produces a faster executable)


Don't build an executable


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


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Readme for madlang-

[back to package description]

Madlang DSL for generating random text

Windows build status 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. The primary way to use Madlang is on the command line using the interpreter, but there is also a partially completed library and EDSL.

Madlang is intended to explore computational creativity and provide an easy way to get started with generative literature.


Binary Releases

Head over to the releases page and grab a binary for your platform.


If you do not see you platform listed, you will have to install from source. Download cabal and GHC. Then:

 $ cabal update
 $ cabal install madlang

You may need to add $HOME/.cabal/bin to your PATH. To do so:

 $ echo 'export PATH=$HOME/.cabal/bin:$PATH' >> $HOME/.bashrc
 $ source $HOME/.bashrc


The smallest program possible in Madlang is simply a return declaration, viz.

    1.0 "heads"
    1.0 "tails"

The :return tells us this that this will be the final value when run, while the numbers in front of the strings denote relative weights. Save this as gambling.mad, and run

 $ madlang run gambling.mad

Now let's try something a little more complicated:

:define person
    1.0 "me"
    1.0 "you"

    1.0 "The only one of us walking out of this room alive is going to be " person "."

A bit more sinister, perhaps. The :define statement there declares a new identifier, which we can later reference. Save this as fate.mad and run:

 $ madlang run fate.mad
 The only one of us walking out of this room alive is going to be you.

We can also refer to another identifier within a :define block.

:define coin
    1.0 "heads"
    1.0 "tails"

:define realisticCoin
    1.0 coin
    0.03 "on its side"

:return realisticCoin

In addition to identifiers, we can also define categories. Categories are just groups of identifiers. We can define one like so:

:define color
    1.0 "yellow"
    1.0 "blue"

:define texture
    1.0 "soft"
    1.0 "scratchy"
    1.0 "dimpled"

:category adjective
    | color
    | texture

    1.0 adjective

Then, when we can adjective, it will pick one of "yellow", "blue",… "dimpled" with equal probability.

Finally, one of the most powerful features of madlang is the ability to include libraries in a file. Open the following and save it as gambling.mad:


:define coin
    1.0 "heads"
    1.0 "tails"

Then, open the following and save it in the same directory as realistic-gambling.mad:

:include gambling.mad

:define realisticGambling
    1.0 gambling-coin
    0.03 "on its side"

    1.0 realisticGambling

Then run it with:

 $ madlang run realistic-gambling.mad

madlang comes with several libraries prepackaged. You can install them for the current user with:

 $ madlang install

Try this out:

:include colors.mad

:define weirdDog
    1.0 colors-color "dog"

    1.0 "On my walk today I saw a " weirdDog "."


There is a Shakespearean insult generator available to test out at my site.



There is a vim plugin available here.

Project Templates

There is a project template bundled with pi, which you can install with

 $ curl -LSfs | sh -s -- --git vmchale/project-init

and invoke with

 $ pi new madlang story


You can view documentation for madlang on Linux, Mac, or BSD by typing:

 $ man madlang



Contributions, bug reports, and feature requests are emphatically welcome. Please see the guide for more specific details.

Release Naming

Releases are named using the releases.mad file found here. You will need to install the standard libraries using

 $ madlang install

before running

 $ just name