
Robert Clausecker
I found out, that GHC implements typeclasses as an extra argument, a record that stores all functions of the typeclass. So I was wondering, is there a way (apart from using newtype) to pass a custom record as the typeclass record, to modify the behavior of the typeclass? I thought about something like this:
f :: Show a => [a] -> String f = (>>= show)
-- So, f becomes something like this? __f :: ClassShow a -> [a] -> String __f (ClassShow __show) x = x >>= __show
-- And if I call the function, it looks somewhat like this: g :: [Int] -> String g = f
__g = __f instanceShowInt
-- But is it possible to do something like this? g2 = __f (ClassShow (return . fromEnum))
Tis is just a random thought, some compilers like JHC implement them by another way. But would this theoretically be possible?
If I understand you right, you would like to decide about the instance at run-time instead of at compile-time. This is actually possible in practice. A suitable search term is "implicit configurations", in particular "reification". Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/