simpleargs-0.2.1: Provides a more flexible getArgs function with better error reporting.

System.SimpleArgs

Description

Provide a getArgs function that is slightly more advanced than the default, without going the entire System.Console.GetOpt route.

The idea is to return a tuple (including the 0-tuple () or 1-tuple) if the supplied arguments match the demands of the program (in number and in type) or a sensible error message if not. The returned tuple must contain elements that are in the Typeable and Read classes.

As an examle, here's a simple line counting program. Here getArgs makes the program take a single parameter, and returns it as a String:

 main = getArgs >>= readFile >>= print . length . lines

This program will take two parameters, a Char and a String:

 main = do
    (ch,name) <- getArgs
    putStrLn (ch:"Name is: "++name)

Documentation

class Args a whereSource

Methods

getArgs :: IO aSource

Return appropriately typed program arguments.

Instances

Args () 
(Read b, Typeable b) => Args b 
(Read x, Typeable x, Read y, Typeable y) => Args (x, y) 
(Read t1, Typeable t1, Read t2, Typeable t2, Read t3, Typeable t3) => Args (t1, t2, t3) 
(Read t1, Typeable t1, Read t2, Typeable t2, Read t3, Typeable t3, Read t4, Typeable t4) => Args (t1, t2, t3, t4) 
(Read t1, Typeable t1, Read t2, Typeable t2, Read t3, Typeable t3, Read t4, Typeable t4, Read t5, Typeable t5) => Args (t1, t2, t3, t4, t5)