
20 May
2012
20 May
'12
2:28 a.m.
Hi, Suppose I have a module of functions with identical signatures: module Functions where a :: Int -> [Int] a x = [x + 1, x + 2, x + 3] b :: Int -> [Int] b x = [x + 4, x + 5, x + 6] and in my main function I receive a command line arguments (a string) naming one of the functions in MyModule. I'd like to lookup and use of the functions by name: lookup :: String -> (Int -> [Int]) lookup "a" = MyModule.a lookup "b" = MyModule.b ... Is there a more idiomatic Haskell way of going about this? I can see there's a fundamental tension between a runtime choice of function name expressed as a string and the need for compile-time known function choice. Thanks, Stu