[Haskell-cafe] bytestring vs. uvector

Don Stewart dons at galois.com
Fri Mar 13 12:34:52 EDT 2009


manlio_perillo:
> Don Stewart ha scritto:
>> bulat.ziganshin:
>>> Hello Don,
>>>
>>> Wednesday, March 11, 2009, 12:12:07 AM, you wrote:
>>>
>>>> Right, so my point stands: there's no difference now. If you can write a
>>>> Storable instance, you can write a UA et al instance.
>>> yes, if there is some class provided for this and not just hard-coded
>>> 4 or so base types 
>>
>> That's right. For example (supporting even pairs):
>>
>>     instance (RealFloat a, UA a) => UA (Complex a) where
>>
>>       newtype UArr  (Complex a)   = UAComplex  (UArr (a :*: a))
>>       newtype MUArr (Complex a) s = MUAComplex (MUArr (a :*: a) s)
>>
>
> You also have to add instance for UIO:
>
>     instance (RealFloat a, UIO a) => UIO (Complex a) where
>         hPutU h (UAComplex arr) = hPutU h arr
>         hGetU h                 = do arr <- hGetU h
>                                      return (UAComplex arr)
>
>
> With Storable, this should not be required; you just have to write an  
> instance for the Storable class.
>



Though you get no IO operations with Storable... UIO is entirely
separate.


More information about the Haskell-Cafe mailing list