Talk:Library for binary

From HaskellWiki
Revision as of 15:53, 7 March 2007 by MathematicalOrchid (talk | contribs) (Fair question...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

What'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)