Hello,<br>I&#39;m trying to use a C++ class in Haskell through C exports.<br>It works all very well, except that when I call the function that deletes the object, it is still valid, I can still call methods on it.<br><br>Here is my Haskell code:<br>

<font face="courier new,monospace"><br>
{-# LANGUAGE ForeignFunctionInterface #-}<br>
  <br>
import Foreign<br>
import Foreign.C.Types<br>
  <br>
newtype PKlass = PKlass (Ptr PKlass)<br>
  <br>
foreign import ccall unsafe &quot;Klass_Create&quot;<br>
  kCreate :: CInt -&gt; CInt -&gt; IO PKlass<br>
  <br>
foreign import ccall unsafe &quot;Klass_Destroy&quot;<br>
  kDestroy :: PKlass -&gt; IO ()<br>
  <br>
foreign import ccall unsafe &quot;Klass_GetX&quot;<br>
  kGetX :: PKlass -&gt; IO CInt<br>
foreign import ccall unsafe &quot;Klass_GetY&quot;<br>
  kGetY :: PKlass -&gt; IO CInt<br>
  <br>
foreign import ccall unsafe &quot;Klass_AddKlass&quot;<br>
  kAdd :: PKlass -&gt; PKlass -&gt; IO PKlass<br>
  <br>
  <br>
main = do<br>
  k &lt;- kCreate 4 5<br>
  kDestroy k<br>
  <b><span style="color: rgb(255, 0, 0);">kGetY k &gt;&gt;= print   -- This shouldn&#39;t work</span></b><br>
  k&#39; &lt;- kCreate 2 8<br>
  k&#39;&#39; &lt;- k `kAdd` k&#39;<br>
  kDestroy k&#39;&#39;<br>
  <b><span style="color: rgb(255, 0, 0);">kGetY k&#39;&#39; &gt;&gt;= print   -- This neither</span></b><br><br><br><font face="arial,helvetica,sans-serif">So it is very basic, and I can&#39;t understand why the supposedly destroyed objects are still here.<br>

Enclosed is all the source code (C++ class, C exportation and the Haskell main hereabove).<br><br>I compile it this way:<br>ghc --make main.hs *.cpp -lstdc++<br></font></font>