[Haskell-cafe] Haskell and symbolic references
Jake McArthur
jake.mcarthur at gmail.com
Fri May 29 12:17:15 EDT 2009
Patrick LeBoutillier wrote:
> Hi all,
>
> Is it possible with Haskell to call a function whose name is contained
> in a String?
> Something like:
>
> five = call_func "add" [2, 3]
You could use Data.Map:
call_func = (funcMap !)
where funcMap = fromList [ ("add", add)
, ("sub", sub)
, ("mul", mul)
, ("div", div)]
Or a version using lookup instead of (!) if you aren't sure that the
string will be a valid function name.
- Jake
More information about the Haskell-Cafe
mailing list