[Haskell-cafe] ANNOUNCE: storable-endian

Eugene Kirpichov ekirpichov at gmail.com
Fri Dec 24 08:49:56 CET 2010


...I mean, storable-endian 0.2.1 actually - 0.2.0 had a stupid bug.

2010/12/24 Eugene Kirpichov <ekirpichov at gmail.com>:
> Hello Hennig,
>
> Thanks for the suggestions!
> I've released storable-endian 0.2.0, which does not use TH and bases
> on your suggestion (though it has a bit of boilerplate because of
> abandoning TH, but I don't think that's critical).
>
> Here's the new source:
> https://github.com/jkff/storable-endian/blob/master/Data/Storable/Endian.hs
>
> 2010/12/23 Henning Thielemann <lemming at henning-thielemann.de>:
>>
>> On Thu, 23 Dec 2010, Henning Thielemann wrote:
>>
>>> On Wed, 22 Dec 2010, Eugene Kirpichov wrote:
>>>
>>>> It defines types like {{Int,Word}{16,32,64},Double,Float}{LE,BE} (for
>>>> example Int32BE) etc. with a corresponding Storable instance.
>>>
>>> How about type constructors LittleEndian and BigEndian?
>>>
>>> newtype LittleEndian a = LittleEndian a
>>>
>>> Maybe using some type classes you can even get rid of Template Haskell and
>>> get plain Haskell 98?
>>
>> Yes, I think you could have (given a module Data.Storable.LittleEndian as
>> LE)
>>
>> instance LE.Storable a => Storable (LittleEndian a) where
>>   sizeOf (LittleEndian a) = sizeOf a
>>   alignment (LittleEndian a) = alignment a
>>   peek p = fmap LittleEndian $ LE.peek p
>>   poke p (LittleEndian a) = LE.poke p a
>>
>> class LE.Storable a where
>>   LE.peek :: Ptr a -> IO a
>>   LE.poke :: Ptr a -> a -> IO ()
>>
>> instance LE.Storable Word16 where
>>   LE.peek p = getWord16le (castPtr p)
>>   LE.poke p = putWord16le (castPtr p)
>>
>> ...
>>
>> I find this much cleaner and simpler to extend to other types.
>>
>
>
>
> --
> Eugene Kirpichov
> Senior Software Engineer,
> Grid Dynamics http://www.griddynamics.com/
>



-- 
Eugene Kirpichov
Senior Software Engineer,
Grid Dynamics http://www.griddynamics.com/



More information about the Haskell-Cafe mailing list