MKHPROG(1)

NAME
mkhprog - make skeleton of a Haskell program

SYNOPSIS
mkhprog [ -l ] [ -m module_name ] [ -o file_name ] [[-flag type] ... ]

DESCRIPTION
mkhprog will make the skeleton of a Haskell program, which includes the code for parsing command line arguments that almost all programs need.

The program so made is normally written to the standard output. It can be placed in a named file by using the -o flag, see below. To get a feel for the generated code, give the command:

    mkhprog -o Main.hs -b Bool -s String -n Int

and look at the program produced in Main.hs.

Flags following any -l, -m or -o options are those to be interpreted by the generated program. Each such flag must be followed by a Haskell type, which is the type of the value associated with that flag by the generated program. Thus

    mkhprog -b Bool -s String -n Int -f Foo

produces a program which interprets a binary flag, b, a flag followed by a string argument, s, a flag followed by an Int argument, n, and a flag followed by an argument of type Foo, f. That program would be invoked, for example, as

    prog -b -n 17 -s string -f "MkFoo 3 True"

assuming MkFoo 3 True is a valid item of type Foo.

A special form of binary flag is available by using +flag Bool instead of -flag Bool : this produces a program which interprets -flag to set an internal value to False, and +flag to set an internal value to True.

Internally, the values of the flags, plus their command line arguments, are passed to a function which can process them as it wishes.

Such values are initialized explicitly to the empty string in the case of Strings, and False in the case of Bools. The user must declare the default value for other types.

The flags interpreted by mkhprog are:

-l  produce a ``literate'' Haskell program, in which lines of code begin with ``> ''.

-m module_name
    Produces a module called module_name rather than the default Main.

-o file_name
    Writes the generated program to file_name rather than the standard output.

POINTS TO NOTE
mkhprog uses the Haskell function reads to read values other than Strings and Bools. Thus, while flags with type String do not need quotes round their argument, any other sorts of String will need quotes. For example, if Bar is a type synonym for String, then a program generated with

    mkhprog -f Bar

will have to be invoked as

    prog -f \"string\"

Some Haskell compilers produce programs whose command line parameters are not all available to a call of getArgs. For example, getArgs may only pick up arguments following an isolated -. Check your documentation for details.

Because mkhprog interprets the -l, -m and -o flags, it can be difficult to generate a program which itself interprets them. The easiest solution to this is to use a flag name which mkhprog does not interpret and then change its name in the generated program.

ACKNOWLEDGEMENTS
The functionality and manual page of mkhprog are based on those of the C program mkprog, though the implementation is entirely different.