I've finally managed to rig my Haskell program so that, at the very end, if I write
let foo = bar :: A
then I get one behaviour, and if I write
let foo = bar :: B
then I get the other desired behaviour.
Now I'd like my program to be able to parse this argument at runtime, but I really have no idea how to proceed. Any advice?
Edit: I'd like to parse some kind of (text) configuration file for which I am free to make up the specification/format.
One possible toy example is reading an integer as either an Int or a Double depending on further context provided in the configuration file, something along the lines of the following in the configuration file
barType: Int
barValue: 2
giving me bar = 2 :: Int, and
barType: Double
barValue: 2
giving me bar = 2 :: Double. Here it could be the case that I should be able to accept any type which has a Num instance.
In my case, I have a type class with some methods, and I'd like to parse anything with an instance for that type class; the methods could do something significantly different depending on the exact type. I don't know how I'd go about writing a Read instance for that.
Thanks.
AandBbased on run-time input?