For anyone that doesn't mind the absurdity of how this is implemented, it should be suitable for "drop in" use.
For those that do mind the absurdity, it nonetheless serves as a proof-of-concept for how far Haskell's reflective capacities can be pushed.
Cheers, and happy hacking, Sterl. Example usage:data Test = Test {t1 :: Int, t2 :: Int, t3 :: String, t4 :: InnerTest} deriving (Data, Typeable, Show)
data InnerTest = InnerTest {t'1 :: Int, t'2 :: Int, t'3 :: String} deriving (Data, Typeable, Show)
testData = Test {t1 = 1, t2 = 2, t3 = "foo", t4 = InnerTest {t'1 = 2, t'2 = 3, t'3 = "bar"}}
*GenericFRef> set t1 23 testDataTest {t1 = 23, t2 = 2, t3 = "foo", t4 = InnerTest {t'1 = 2, t'2 = 3, t'3 = "bar"}}
*GenericFRef> set (t'1 `o` t4) 23 testDataTest {t1 = 1, t2 = 2, t3 = "foo", t4 = InnerTest {t'1 = 23, t'2 = 3, t'3 = "bar"}}
*GenericFRef> update (t2) (\x->x*x) testDataTest {t1 = 1, t2 = 4, t3 = "foo", t4 = InnerTest {t'1 = 2, t'2 = 3, t'3 = "bar"}}
*GenericFRef> update (t'2 `o` t4) (\x->x*x) testDataTest {t1 = 1, t2 = 2, t3 = "foo", t4 = InnerTest {t'1 = 2, t'2 = 9, t'3 = "bar"}}
p.s. I have a nagging sensation that somebody may have done this before, although I can't trace the source.
GenericFRef.hs
Description: Binary data
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
