I want to do something like this in Haskell, but the compiler is not letting me.
Is there any way to accomplish this task?
-- both modules export function named "hello"
-- and I want to run it in every module
import qualified MyMod as M1
import qualified MyAnotherMod as M2
runmodules = map (\m -> m.hello) [M1, M2]
I don’t think you can quote a qualified name prefix like that in template haskell, and the
helloidentifier isn’t in scope, so you might have to fall back to programming with strings.which can then be used like so,
However, I would not do all this. You could just write
[M1.hello, M2.hello]or use a type class to abstract over implementations.