Request: withArrayLength

Adrian Hey <[email protected]> Wed, 11 Feb 2004 09:55:00 +0000
Newsgroups gmane.comp.lang.haskell.ffi
Message-ID <[email protected]>
Hello,

The FFI currently provides..

 withArray :: Storable a => [a] -> (Ptr a -> IO b) -> IO b

I think..

 withArrayLength :: Storable a => [a] -> (Ptr a -> Int -> IO b) -> IO b

would be useful because you often need the length in a foreign function
and I guess withArray must pre-calculate the length before allocating
storage in any case (or at least must know the length by the time
marshalling is finished).

It seems a pity to waste time calculating it twice.

Actually, looking at the ffi again I see there is something similar
for CStrings already, but not for arrays in general. Is this an
oversight or a deliberate decision?

Regards
--
Adrian Hey