[Haskell-cafe] FW: Treating command-line arguments as a Haskell
ndmitchell at gmail.com
Mon Dec 24 12:04:14 EST 2007
> I want to call a function from within Haskell module so that the name
> of this function corresponds to my first command-line argument and the
> rest rest of the command-line arguments are would become themselves
> the argument to this function.
While you can do this, you probably don't actually want to.
You probably have one of two scenarios in mind:
1) You want to test the program. Use ghci or hugs for this, which lets
you type in expressions and then evaluates them.
2) You only intend their to be a subset of functions which can be
invoked. With higher order functions this is easy:
functions = [("foo",foo), ("bar",bar)]
main = do
(name:cmds) <- getArgs
case lookup name functions of
Nothing -> putStrLn "Function not found"
Just f -> f cmds
Note to the mailing list: When someone says it is their first week of
Haskell, answers should probably include phrases like "pattern match"
or "higher order" - not Template Haskell, hs-plugins, HList, GADT's
More information about the Haskell-Cafe