The ST
monad is really intended for working with Haskell-allocated state like STRef
and STArray
.
If the things you want to call out to don't have externally visible side-effects and just manipulate the structures you'll be passing them, it's probably "morally" ok to use unsafeIOToST
to call them.
You'll need to take care that you don't let your pointers escape the specific ST
computation they are used in as you won't get the normal safety benefits guaranteed by the phantom s
parameter to ST
.
Using STRef (ForeignPtr ...)
won't really help in itself, but perhaps you might use a newtype
wrapper that uses the phantom type parameter s
to give a little extra self-imposed safety.