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

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to