dimanche 23 janvier 2022

Haskell Beginner, Calling Functions by their Names

Trying the 99 puzzles to learning Haskell. A quality-of-life problem that I have is that every time I test a solution, I would write a function:

mySolutionForQuestion12 :: someFunctionType

testMySolutionForQuestion12 :: IO ()
testMySolutionForQuestion12 = do
    print "testMySolution"
    print $ mySolutionForQuestion12 "myInput1"
    print $ mySolutionForQuestion12 "myInput2"
    putStr "\n"

main = do
    -- neglected code to test solutions for question 1 up to 11 --
    testMySolutionForQuestion12
    ...

    -- instead I want to do something like --
    callAllFunctionsInThisFileByNameBeginningWith "test"
    -- , so that I only have to write one line of code instead of n lines --

To be able to be as lazy as possible, I would love to have a way to make my main automatically call all functions that begin with the 4 exact characters test in my .hs file.

Is this possible in Haskell? Coming from Python, for Python a dynamic language this is self evident, but for C or C++ this would need quite a workaround (I don't actually know how to do that in these languages)

I am wondering thus how would Haskellians (if this is a word?) approach this? Is there some "best practice" in this regard?





Aucun commentaire:

Enregistrer un commentaire