
16 Aug
2009
16 Aug
'09
6:45 a.m.
I have to write a function which calls a function with unknown (i.e. given in runtime) number and type of arguments. 1. Use closure implementation from Gtk2Hs. Pros: Written Cons: Not in haskell 2. Use unsafeCoerce. Something like: f a b = return (a + b) f' = unsafeCoerce (f :: Int -> Int -> IO Int) :: IO () unsafeCoerce (unsafeCoerce ((unsafeCoerce f' :: Int -> IO ()) 5) :: Int -> IO ()) 4 :: IO Int (of course it is an example in fact it will be not only Int etc.) Personally I'd prefere in-haskell solution as: - Rts API used by Gtk2Hs is 'semi-public' - It is GHC-specific (?) but I'm not sure if my solution is safe. Regards