The madlang package

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

Please see README.md


[Skip to Readme]

Properties

Versions 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
Dependencies ansi-wl-pprint, base (>=4.7 && <5), composition, containers, directory, file-embed-poly, madlang, megaparsec, microlens, MonadRandom, mtl, optparse-applicative, random-shuffle, template-haskell, text [details]
License BSD3
Copyright Copyright: (c) 2016 Vanessa McHale
Author Vanessa McHale
Maintainer tmchale@wisc.edu
Category Web
Home page https://github.com/vmchale/madlang#readme
Source repository head: git clone https://github.com/vmchale/madlang
Uploaded Thu Apr 20 02:52:29 UTC 2017 by vmchale
Distributions NixOS:2.3.0.3
Downloads 759 total (489 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-04-20 [all 1 reports]

Modules

[Index]

Flags

NameDescriptionDefaultType
llvm-fastEnable build with llvm backendDisabledAutomatic

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

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for madlang

Readme for madlang-2.3.0.3

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.

It is an interpreted language, written in Haskell. It runs from the command line, but it is also a Haskell library that can be integrated into other projects.

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 the Markov chains that are often used to generate text.

Examples

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
:return
    0.7 person fortune
    0.1 intense
    0.2 goodfortune

Syntax

There are two keywords 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.

There is also a Shakespearean insult generator demo available in demo/shakespeare.mad

Using the library

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

 λ:> runFile [] "demo/shakespeare.mad"
 "Thou hasty-witted gleeking puttock!"

Haddock documentation of all library functionality is located here.

Installation

Releases

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

Nix

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

Download nix with

curl https://nixos.org/nix/install | sh

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

Stack

Download stack with

curl -sSL http://haskellstack.org | 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.

Use

To use it, try

 $ madlang run demo/shakespeare.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.