UnsafePerformIO when accessing C dependent resources

I am writing bindings (for the first time). At level C there is a function of allocating some resource, let him name it ParentRes. He returns IO (Ptr ParentRes). It is created every time ParentRes, a child resource is allocated, name it ChildRes. This material is static, the child pointer cannot change and is freed when the parent resource is freed.

Now catch: there is a function that takes a pointer to a parent and returns a pointer to a child:

foreign import ccall unsafe "…"
  c_get_child_res :: Ptr ParentRes -> IO (Ptr ChildRes)

I want to write a type wrapper Ptr ParentRes -> Ptr ChildResusing unsafePerformIO. Is there a reason I should not do this?

+4
source share
1 answer

, , "" , .

: , IO. IO monad - Haskell . , IO.

, , , , , . , ( ), . , IO.

, . .

+2

Source: https://habr.com/ru/post/1613671/


All Articles