[Haskell-cafe] Linking to third party libraries in windows

Matthew Bromberg mattcbro at earthlink.net
Fri May 26 03:50:28 EDT 2006


Not only does your suggestion make more sense than what I was doing, but 
also
it causes the 'matrices' to behave as expected, namely to have the side 
effects
incorporated into their array values.

I can't say I fully understand why this is true.  In both cases I was 
wrapping Rmatrix in
a monad after every computation.  The difference is that the array 
component  had an
additional monad wrapper around and now it doesn't.  That is,

old case
newtype Rmatrix = Rmatrix (Int, Int,  IO(StorableArray Int CDouble))

new case
newtype Rmatrix = Rmatrix (Int, Int,  StorableArray Int CDouble)

In the old way, the additional IO wrapper forces an additional nesting 
of do loops for most processing.
It is certainly the case that the do loop that performs the 
withStorableArray operations has the contents
of the array modified.  Outside that loop, once all actions on the monad 
are done, I am not convinced the
array will mutate unless it's explicitly returned.

Now hopefully I won't induce unnecessary copying.  Thanks again for your 
help.

Brian Hulley wrote:
>
> Hi Matthew -
> Sorry about the long delay in my reply to your last message - I'd 
> composed the reply but when I tried to send it I was blocked by 
> spamhaus.com because the dynamic IP that my ISP had allocated to me at 
> the time I was connected had been listed on some composite spam 
> blocker database, and even when I tried reconnecting several times I 
> kept ending up being allocated the same client IP. So I did a complete 
> scan of my system and now (several hours later) when I tried to 
> reconnect again, I've been allocated a different client IP so my reply 
> to your last message was sent at last! ...
>
> I hope it answers your question relating to the above: the array is 
> not created in the let statement, but twice, in
>      rout <- mac r2 (-0.5) rmat
> and then again in
>      mprint r2
>
> Rmatrix really needs to have type (Int, Int, StorableArray Int 
> CDouble) if your intention is to pass around an actual allocated 
> matrix together with its dimensions, and listtoRmatrix would need to 
> be typed as:
>
>      listtoRmatrix :: Int -> Int -> IO Rmatrix
>
> so that the let statement could be replaced by
>
>      r2 <- listtoRmatrix 3 2 [1, 1, 1, 1, 1, 1]
>
> and for example mprint would be defined as:
>
>      mprint :: Rmatrix -> IO ()
>      mprint (Rmatrix cols rows arr) = do
>               -- just print element at (0,0) for the moment
>               readArray arr 0 >>= print
>
> (Of course the above needs to iterate through the rows cols etc but 
> you've already got the code to do this...)
>
> Hope this helps,
>
> Brian.
>


More information about the Haskell-Cafe mailing list