I have a problem. I've almost done exception handling in my Haskell<->OCaml interface. Exceptions from either side are propagated through the other (and are not wrapped twice when cross languages more than once). Haskell functions are converted to OCaml functions with two methods. One of them takes a Haskell closure (of type, among others, Value -> Value -> Value, where Value is the type of OCaml values wrapped inside a ForeignObj) and produces a Value which has the appropriate function type on the OCaml side. When executed, it raises an OCaml exception when the Haskell function threw a Haskell exception. No problem here. The second method looks like this: -------- HASKELL ------------------------------------------------------- someFun:: Val -> Val -> IO Val -- Val is the raw OCaml value (type "value" in OCaml's C interface). someFun = exportFun (some_Haskell_function :: Value -> Value -> Value) foreign export someFun :: Val -> Val -> IO Val -------- OCAML --------------------------------------------------------- external some_fun : 'a list -> int -> 'a list = "someFun" ------------------------------------------------------------------------ Exceptions don't work here. I know why, but I don't know how to do them. OCaml's FFI provides C functions that raise OCaml exceptions. They act similarly to longjmp() - magically transfer control from the C function they are called in to the right place. In the first method, they last thing before OCaml was a concrete C function written by me. It can be safely escaped - OCaml's rts takes care of handling exceptions in such cases. But in the second method the function is foreign exported from Haskell. The only thing between Haskell and OCaml is the generated C function sitting in the *_stub.c file. It is not safe to simply escape the Haskell code. I have no way of getting my hands between the exported Haskell function and the external world, nor safe shutting down the Haskell thread from some appropriate place. Help! Of course I could make a C wrapper for each exported function that may throw exceptions, but the principle is that one should not be required to write C in order to interface between Haskell and OCaml. Or I could use the first method, but it is not convenient: -------- HASKELL ------------------------------------------------------- someFun:: Val -> IO Val someFun = exportFun (fun (some_Haskell_function :: Value->Value->Value)) -- fun is the first method. foreign export someFun :: Val -> IO Val -------- OCAML --------------------------------------------------------- type 'a my_list_fun = 'a list -> int -> 'a list external some_fun' : unit -> 'a my_list_fun = "someFun" let some_fun x = some_fun' () x (* Eta-expanded: OCaml also has its monomorphism restriction :-) *) ------------------------------------------------------------------------ -- __("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/ \__/ GCS/M d- s+:-- a22 C+++$ UL++>++++$ P+++ L++>++++$ E- ^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-