Suggestion re Data.Storable.Array

Simon Marlow simonmar at microsoft.com
Thu Apr 21 05:41:20 EDT 2005


On 21 April 2005 02:10, Paul Steckler wrote:

>   I recently needed to access C-like arrays
> from Haskell.  Everyone pointed me to
> Data.Storable.Array, but that wasn't quite
> what I wanted.  The MArray class that provides
> the interface for storable arrays insists that
> it create the storage via newArray or newArray_.
> But I already had the C storage I needed; I justed
> wanted to wrap that in Haskell.
> 
>   I cons'ed up my own primitives, which work just
> fine, but it would be nice to just use something
> already in the libraries.  Concretely, adding
> a way to create a storable array from an existing
> Ptr would've done the trick.  I can see that's
> less safe, but sometimes you have to live
> dangerously!

Ok, I've added a suitable back door:

 unsafeForeignPtrToStorableArray 
   :: ForeignPtr e -> (i,i) -> IO (StorableArray i e)

Cheers,
	Simon


More information about the Libraries mailing list