In Haskell, the error function has signature String -> a. It can return any type because it never actually returns. (It prints its argument and terminates the program.)
I've written a function in C that does something similar. It logs the string that is passed and terminates the process. Is there a way I can write a Haskell wrapper to have the same signature as error?
The C function has the form void RaiseError(char* msg) { ... }
So far, I have
foreign import capi safe "file.h RaiseError"
c_RaiseError :: CString -> IO ()
raiseError :: String -> a
raiseError msg = unsafePerformIO $ do
withCString msg c_RaiseError -- Does not return
return (error "") -- Never gets called
There must be a more elegant way to do this.