I defined a lot of functions (say, 100+), each of which does a certain job, but with the same signature. This is something like:
module R001 (run) where run = <do-...>
module R002 (run) where run = <do-...>
What I want to do is provide the actual “launch” as user input so that:
main = do
runWith $ read $ getLine
where
runWith :: Int -> IO ()
runWith n = R<n-padded-with-0>.run
I am currently importing all modules and putting everything runin a list [Maybe (IO())], so this works:
runWith n = case Rs !! (read $ getLine) of
Just run -> run
Nothing -> undefined
But as nI grow, I must constantly maintain a large list.
Is there a way to define a large list using TemplateHaskell or just load the appropriate module as needed at runtime without separating each module from different shared libraries.
epsilonhalbe :
import R1 (run1)
import R2 (run2)
test = $(functionExtractor "^run")
main :: IO ()
main = do
putStrLn $ show $ length $ test
run1 -- remove on second attempt
run2 -- remove on second attempt
2 run1 run2. , 0. , , , , ...