...I mean, storable-endian 0.2.1 actually - 0.2.0 had a stupid bug. 2010/12/24 Eugene Kirpichov <[email protected]>: > 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 <[email protected]>: >> >> 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 [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
