[Haskell-cafe] ANNOUNCE: storable-endian

Gábor Lehel illissius at gmail.com
Fri Dec 24 09:44:06 CET 2010


One further idea -- assuming HasBigEndian and HasLittleEndian are
unexported because you don't want people writing new instances -- is
to have something like class HasBigEndianPrivate => HasBigEndian
instead, with the latter exported and the former not, and instances of
each for the same types. What you gain is HasBigEndian and its
instances showing up in the docs, and being able to use it in type
signatures (while still not being able to write new instances).

On Fri, Dec 24, 2010 at 8:49 AM, Eugene Kirpichov <ekirpichov at gmail.com> wrote:
> ...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/
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Work is punishment for failing to procrastinate effectively.



More information about the Haskell-Cafe mailing list