[Haskell-cafe] broken IO support in uvector package, when using non primitive types

Don Stewart dons at galois.com
Fri Mar 13 18:53:53 EDT 2009


manlio_perillo:
> Daniel Fischer ha scritto:
>> [...]
>> Worked with uvector-0.1.0.1:
>>
>>  [...]
>> But not with uvector-0.2
> > [...]
>
> The main difference is that in uvector 0.2, hPutBU does not write in the  
> file the length of the array; hGetBU simply use the file size.
>
>    let elemSize = sizeBU 1 (undefined :: e)
>    n <- fmap ((`div`elemSize) . fromInteger) $ hFileSize h
>
>
> So, the problem seems to be here.
> This simply don't support having two arrays written in the same file,  
> and sizeBU belongs to the UAE class, whose instances are only declared  
> for builtin types.
>
>
> So, the patch is: "just revert this change".

Or... use your own UIO instance. That's why it's a type class!

Anyway, for the background on this:

    Tue Nov 18 08:44:46 PST 2008 Malcolm Wallace
      * Use hFileSize to determine arraysize, rather than encoding it in the
      file.

    "Here is a patch to the uvector library that fixes hGetBU and hPutBU to
    use the filesize to determine arraysize, rather than encoding it within
    the file.  I guess the disadvantages are that now only one array can
    live in a file, and the given Handle must indeed be a file, not a socket
    Handle.  But the advantage is that one can read packed raw datafiles
    obtained externally."

Still, again, I'd point out that uvector is alpha, APIs can and will
change. 

-- Don


More information about the Haskell-Cafe mailing list