If you call functions in a DLL from Haskell, there is no safety net which prevents the DLL from messing with you process' address space. I see three options here:
- If the DLL has a sane API, it will be possible to determine if the call will succeed before messing up. You could even enforce "proper use" by expressing these conditions in Haskell's type system. This way, when your Haskell code compiles, you won't have runtime crashes from the DLL as well.
- It is not uncommon for DLLs to offer a function to check if the last call caused an error. Maybe you want to explore this direction.
- If by "crashing" you mean that the call causes an segmentation fault or the like, there's not much Haskell / GHC / the runtime can do about it. You might isolate the problem by doing the calls to the DLL from a separate process, spawned from your main process. This obviously introduces a performance cost for spawning the child processes and passing the data around.