Difference between revisions of "Talk:Library for binary"
Jump to navigation
Jump to search
(Fair question...) |
|||
Line 1: | Line 1: | ||
What's the difference between this and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Bits.html Data.Bits]? -- [[User:EricKow|kowey]] 14:55, 7 March 2007 (UTC) |
What's the difference between this and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Bits.html Data.Bits]? -- [[User:EricKow|kowey]] 14:55, 7 March 2007 (UTC) |
||
+ | |||
+ | <hask>Data.Bits</hask> 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 |
||
+ | |||
+ | <haskell> |
||
+ | 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 |
||
+ | </haskell> |
||
+ | |||
+ | I don't see a way to do that (easily) with <hask>Data.Bits</hask>. (In particular, if you encode bits as a plain integer, how to you tell the difference between 0 and 000? With a list encoding, <hask>[Zero]</hask> and <hask>[Zero,Zero,Zero]</hask> are quite distinct.) |
||
+ | |||
+ | In summary, you could say that this library is for solving a slightly different problem. [[User:MathematicalOrchid|MathematicalOrchid]] 15:53, 7 March 2007 (UTC) |
Latest revision as of 15:53, 7 March 2007
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)