
Hey guys, At work we have many and varied needs to do bytewise operations on Haskell data. Things like: toBigEndian rotateBytes etc. Has anyone thought about: * A "Bytes" class, like the Bits class? Providing standard operations on values treated as bytes? * An Endian class, a la fromIntegral, for flipping bytes into a particular endianness. -- Don

Don Stewart schrieb:
Hey guys,
At work we have many and varied needs to do bytewise operations on Haskell data. Things like:
toBigEndian rotateBytes
etc.
Has anyone thought about:
* A "Bytes" class, like the Bits class? Providing standard operations on values treated as bytes?
* An Endian class, a la fromIntegral, for flipping bytes into a particular endianness.
In contrast to Data.Bits it should use the proper parameter order, e.g. rotateBytes :: Int -> a -> a

lemming:
Don Stewart schrieb:
Hey guys,
At work we have many and varied needs to do bytewise operations on Haskell data. Things like:
toBigEndian rotateBytes
etc.
Has anyone thought about:
* A "Bytes" class, like the Bits class? Providing standard operations on values treated as bytes?
* An Endian class, a la fromIntegral, for flipping bytes into a particular endianness.
In contrast to Data.Bits it should use the proper parameter order, e.g. rotateBytes :: Int -> a -> a
Proper in the Okasaki sense?

On Thu, 19 Feb 2009, Don Stewart wrote:
lemming:
In contrast to Data.Bits it should use the proper parameter order, e.g. rotateBytes :: Int -> a -> a
Proper in the Okasaki sense?
Unfortunately I don't know what Okasaki's sense is, but I refered to this one: http://haskell.org/haskellwiki/Parameter_order

lemming:
On Thu, 19 Feb 2009, Don Stewart wrote:
lemming:
In contrast to Data.Bits it should use the proper parameter order, e.g. rotateBytes :: Int -> a -> a
Proper in the Okasaki sense?
Unfortunately I don't know what Okasaki's sense is, but I refered to this one: http://haskell.org/haskellwiki/Parameter_order
You made me go and dig through the archives! http://article.gmane.org/gmane.comp.lang.haskell.libraries/3650/ http://article.gmane.org/gmane.comp.lang.haskell.libraries/3654/ In response to questions about why the convention of putting the data structure as the last argument... This style supports multiple operations nicely, especially with combined with the $ operator. For example, to insert 3 elements into a set, you can say insert 1 $ insert 2 $ insert 3 $ someSet (the last $ is optional). With the other argument ordering, you would say insert (insert (insert someSet 3) 2) 1 See the entire thread: http://thread.gmane.org/gmane.comp.lang.haskell.libraries/3622/focus=3650 from 2005. -- Don

You might want to make it more general than byte and byte-vector (or
whatever it is you imagine rotating).
The endian problem occurs anytime a sequence of smaller units are
aggregated to a larger unit.
So it could be bits in a word, 8-bit bytes in a vector, nybbles in a byte, etc.
On Thu, Feb 19, 2009 at 7:12 PM, Don Stewart
Hey guys,
At work we have many and varied needs to do bytewise operations on Haskell data. Things like:
toBigEndian rotateBytes
etc.
Has anyone thought about:
* A "Bytes" class, like the Bits class? Providing standard operations on values treated as bytes?
* An Endian class, a la fromIntegral, for flipping bytes into a particular endianness.
-- Don _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On 2009 Feb 19, at 13:12, Don Stewart wrote:
At work we have many and varied needs to do bytewise operations on Haskell data. Things like:
toBigEndian rotateBytes
etc.
Has anyone thought about:
* A "Bytes" class, like the Bits class? Providing standard operations on values treated as bytes?
* An Endian class, a la fromIntegral, for flipping bytes into a particular endianness.
I'd think these would be additions to the Word* types, reorganized under a Word class. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

dons:
Hey guys,
At work we have many and varied needs to do bytewise operations on Haskell data. Things like:
toBigEndian rotateBytes
etc.
Has anyone thought about:
* A "Bytes" class, like the Bits class? Providing standard operations on values treated as bytes?
* An Endian class, a la fromIntegral, for flipping bytes into a particular endianness.
I found http://hackage.haskell.org/packages/archive/byteorder/1.0.0/doc/html/System-... http://hackage.haskell.org/cgi-bin/hackage-scripts/package/byteorder-1.0.0 On Hackage. which does a few things in this area.
participants (4)
-
Brandon S. Allbery KF8NH
-
Don Stewart
-
Henning Thielemann
-
Lennart Augustsson