How to dynamically call a function that is defined in several modules in the same signature

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. , , , , ...

+5
2

haskell , , .

regexp userinput . , "", ,

import R*.hs (run)

run1 = …, run2 = … , .

{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.Extract
import myRunFunctions

main = do
     let listOfRuns = $(functionExtractor "^run")
     putStrLn "please choose a run"
     putStrLn $ show listOfRuns
     let run = runWith $ read $ getLine
     run
   where
     runWith n = listOfRuns !! n

: , , haskell

,


:
run* , , - Nucleotide Project Rules.hs Nucleotide.hs.

Runs.hs

module Runs where
import Language.Haskell.Extract

listOfRuns = map snd $(functionExtractor "^run")

run1 = …
run2 = …

Main.hs

import Runs

main = do
     putStrLn "please choose a run"
     putStrLn $ show listOfRuns
     let run = runWith $ read $ getLine
     run
  where
    runWith n = listOfRuns !! n

+5

, run ? , run Int ( Integer, ).

module AllMyCircuits where
run 0 = {- do blah blah blah -}
run 1 = {- do blah blah blah -}
run 2 = {- do yikes -}

module Main where
import AllMyCircuits
main = readLn >>= run
+1

All Articles