[Haskell-cafe] FW: Treating command-line arguments as a Haskell
expression
Neil Mitchell
ndmitchell at gmail.com
Mon Dec 24 12:04:14 EST 2007
Hi
> 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
Thanks
Neil
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
etc!
More information about the Haskell-Cafe
mailing list