Talk:Library for binary
Add topicWhat's the difference between this and Data.Bits? -- kowey 14:55, 7 March 2007 (UTC)
Data.Bits
provides bitwise operations on integers. This library represents a collection of bits explicitly, as a Haskell list. That means that all of Haskell's list processing functions are available to you. It's also means you can do things like
data Tree t = Leaf t | Branch (Tree t) (Tree t)
get_node :: Bits -> Tree t -> Tree t
get_node [] t = t
get_node (b:bs) (Branch t0 t1) = get_node bs $ if b == Zero then t0 else t1
I don't see a way to do that (easily) with Data.Bits
. (In particular, if you encode bits as a plain integer, how to you tell the difference between 0 and 000? With a list encoding, [Zero]
and [Zero,Zero,Zero]
are quite distinct.)
In summary, you could say that this library is for solving a slightly different problem. MathematicalOrchid 15:53, 7 March 2007 (UTC)