-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add instance of class Bits
for byte strings?
#383
Comments
I'm +0.5 in favor of this, but would like to hear from others. What kind of behavior for strings of unequal length do you have in mind? Could we just use
|
It is already enough trouble to mediate between character lists (used by some older or simpler libraries) and byte arrays (used by some newer or more sophisticated libraries). I would rather not add another type conversion. All I want is to play Crypto Hack with Haskell rather than Python (as they advise), and it is so messy already. I want convenience. The behaviour I am looking for is the same as in the |
I don't have a good idea of the tradeoffs involved in such an instance. I think a draft implementation would help me make up my mind. |
this comment describes some reasons and points to some other reasons why I'm -1 on this (particularly @ekmett's comment on the reddit thread). Furthermore, |
What if we add a function |
Or even more general (and useful) |
This is the argument of Edward Kmett from the Reddit thread mentioned above, for reference:
I am going to engage with it presently. I dislike partial functions as much as the next person, but the reality is that we are going to have some. You cannot set bit №9 of a byte, you cannot divide by 0, and so on. This is life, we should get over it somehow. The usual interpretation of So what is the infinite correspondent of an empty byte string? There is no natural definition. I do not see this terrible revelation preventing people from using On the good side, under this «infinitely looping» definition of logical connectives we have no problem defining the complement operation, since Another way to look at it is like this: logical connectives are defined for bits, so all we have to do is define the shape where bits are located. Finite byte strings have the shape of a sequence indexed by finite ordinals, so for a byte string u the set of indices is {n ∈ ℕ, n ≤ |u|}. At the limit, infinite byte strings are indexed by ℕ. What more to wish for? |
Unfortunately, there is no way to make operations defined this way associative. For example, suppose we have a long message m and two keys k₁ of length 2 and k₂ of length 3. Applying these keys to the message with This means that the appropriate setting for these computations is infinite byte streams, or perhaps infinite byte streams decorated with length, either of which is out of scope for this package. |
I assume this can be closed?.. Feel free to reopen, if I misjudged the conversation. |
There is a class in
base
that implementsxor
and other bit operations. I wonder if we can add an instance of this class for byte strings. There is already a packagexor
that defines these operations between byte strings and words — this suggests that the feature is useful and not trivial.The text was updated successfully, but these errors were encountered: