madlang: Randomized templating language DSL

[ bsd3, library, text ] [ Propose Tags ] [ Report a vulnerability ]

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


[Skip to Readme]

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
development

Turn on '-Werror'

Disabled
library

Don't build an executable

Disabled

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

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 1.0.0.0, 1.0.0.1, 1.0.1.0, 1.1.1.0, 1.1.2.0, 1.1.3.0, 2.0.0.0, 2.0.0.1, 2.0.1.0, 2.0.1.1, 2.0.1.2, 2.1.0.0, 2.1.0.1, 2.1.0.2, 2.1.0.3, 2.1.0.4, 2.1.1.0, 2.1.1.1, 2.1.1.2, 2.1.1.3, 2.1.2.0, 2.2.0.1, 2.3.0.2, 2.3.0.3, 2.3.0.4, 2.3.0.5, 2.3.0.6, 2.3.1.0, 2.3.1.1, 2.3.2.0, 2.4.0.0, 2.4.0.1, 2.4.0.2, 2.4.1.0, 2.4.1.1, 2.4.1.2, 2.4.1.3, 2.4.1.4, 2.4.1.5, 2.4.1.6, 2.4.2.0, 2.4.2.1, 2.4.2.2, 2.4.2.3, 2.4.2.4, 2.4.2.5, 2.4.2.6, 2.4.2.7, 2.4.2.8, 2.4.2.10, 2.4.2.11, 2.4.2.12, 2.4.2.13, 2.4.2.14, 2.4.2.20, 2.4.2.21, 2.4.2.22, 2.4.2.25, 3.0.0.0, 3.0.0.1, 3.0.0.3, 3.0.0.4, 3.1.0.0, 3.1.0.1, 3.1.0.2, 3.1.0.5, 3.1.0.6, 3.1.0.7, 3.1.0.10, 3.1.1.0, 3.1.1.1, 3.1.1.6, 3.1.1.7, 3.1.1.13, 3.1.1.18, 3.1.1.20, 3.1.1.21, 3.1.2.0, 3.2.0.0, 3.2.0.1, 4.0.0.0, 4.0.0.1, 4.0.0.2, 4.0.0.3, 4.0.0.4, 4.0.1.0, 4.0.1.1, 4.0.2.0, 4.0.2.1, 4.0.2.2, 4.0.2.5, 4.0.2.6, 4.0.2.7, 4.0.2.8, 4.0.2.9, 4.0.2.11, 4.0.2.12, 4.0.2.13, 4.0.2.14, 4.0.2.15, 4.0.2.16
Change log CHANGELOG.md
Dependencies ansi-wl-pprint, base (>=4.11 && <5), binary, composition-prelude (>=2.0.2.0), containers, directory, file-embed, filepath, http-client, http-client-tls, madlang, megaparsec (>=7.0), MonadRandom, mtl, optparse-applicative, random-shuffle, recursion (>=2.2.3.0), tar, template-haskell, text, th-lift-instances, titlecase (>=1.0), zip-archive, zlib [details]
Tested with ghc ==8.6.5, ghc ==8.4.4
License BSD-3-Clause
Copyright Copyright: (c) 2016-2019 Vanessa McHale
Author Vanessa McHale
Maintainer vamchale@gmail.com
Category Text
Source repo head: darcs get https://hub.darcs.net/vmchale/madlang
Uploaded by vmchale at 2019-11-09T00:45:10Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables madlang
Downloads 62720 total (129 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-11-09 [all 1 reports]

Readme for madlang-4.0.2.16

[back to package description]

Madlang DSL for generating random text

Windows build status Build Status Hackage

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. Madlang can be used as an EDSL for Haskell or using the command-line interpreter.

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

Installation

Binary Releases

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

Cabal

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

 $ cabal update
 $ cabal new-install madlang

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

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

Tutorial

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

:return
    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
 heads

Now let's try something a little more complicated:

:define person
    1.0 "me"
    1.0 "you"

:return
    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

:return
    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:

:library

: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"

:return
    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"

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

EDSL

You can use Madlang as a Haskell EDSL, generating values of type RandTok. This can be done a couple ways. One is to use the file embedder:

randomText :: RandTok
randomText = $(madFile "mad-src/some-bot.mad")

While the other is to use the madlang quasi-quoter:

randomText :: RandTok
randomText = [madlang|
:include adjectives.mad

:return
    1.0 "I am feeling very " adjectives-adjective " today."
|]

You can then transform this into a random text file with:

generateText :: IO Text
generateText = run randomText

Examples

There is a Shakespearean insult generator available to test out at my site. For a look at using Madlang as an EDSL, check out my recursion scheme generator

Tooling

Vim

There is a vim plugin available here.

Project Templates

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

 $ curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git vmchale/project-init

and invoke with

 $ pi new madlang story

There is also a templated project here that can be invoked via

pi git vmchale/https://github.com/vmchale/madlang-miso story

Manpages

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

 $ man madlang

Contributions

Guide

Contributions, bug reports, and feature requests are emphatically welcome. Please see the CONTRIBUTING.md 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