-
Notifications
You must be signed in to change notification settings - Fork 10
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
Alternative instance #3
Comments
I didn't plan on adding Alternative for BitGet, but it's probably doable by piggybacking on the Alternative instance for Get. I didn't get from your code snippet above what you're trying to do? |
I'm trying to emulate The actual problem is that I'm working on a binary format for which the spec says: "there're some records in these N bytes, decode them like this until you run out of data". It turns out that after decoding some records, there're padding bits left, and the parser tries decoding these bits as the next record and fails with "not enough bytes". |
Ah, I see. |
I tend to disagree that it would be easier to use. Easier to implement - definetely (it looks like a lot of changes are required to implement Alternative, probably mirroring the code for Get monad), but nothing can compete with high-level construct like |
A subtile problem with In contrast, a function that keeps trying a decoder if there is at least 7 bits left, no surprises there. Since |
Okay, here's my attempt: polachok@8284c5b |
I'm afraid it's not the best approach. I believe Alternative could be implemented with much less effort, by reusing the Alternative implementation from I imagine that it could be done by piggybacking on
The testing is quite superficial. Implementing Alternative introduces a lot of new code paths since there is a main computation but also a fallback computation for when the main computation fails. Not only the BitGet state must be managed, but also the state of Get. |
Well, it turns out isEmpty is not actually sufficient for my needs (but useful anyway).
oops, "demandInput: not enough bytes"
I'd be glad to hear suggestions on how to implement Alternative instance for BitGet.
The text was updated successfully, but these errors were encountered: