[Haskell-cafe] Medical Instruments -> Jason

Ben Millwood haskell at benmachine.co.uk
Wed Nov 11 14:24:21 EST 2009

On Wed, Nov 11, 2009 at 6:00 PM, Philippos Apolinarius
<phi500ac at yahoo.ca> wrote:
>  closecport :: Int -> IO Int
>  closecport n= return (fromIntegral (c_closecport (fromIntegral n)))

The return here doesn't do what you think it does - semantically, the
value of c_closecport is still considered pure and assumed to be
referentially transparent, so multiple calls to closecport are allowed
to share the value returned, or delay the call until the value is
unwrapped, call it multiple times for each use of the value, or
anything else. You need to use IO *directly* in the foreign import
declaration so that the compiler knows that the function calls can't
be shared or inlined or generally messed about with: the IO tells it
that order of execution with respect to your other IO actions is
This one looks the most right:
foreign import stdcall unsafe "rs232.h closecport" closecport :: IO ()
so I think you need to look closer about why it wasn't working for
you, and where or how you were using it.

More information about the Haskell-Cafe mailing list