Closed devesascampos closed 1 year ago
I understand if this is expected behaviour (and the example is wrong) and I should just use bools
# match%bitstring bs with | {| false:1: |} -> "working";;
- : string = "working"
# match%bitstring bs with | {| true:1: |} -> "working";;
Exception: Match_failure ("//toplevel//", 1, 0).
but to me it strikes me as weird to be able to match 0b01
but not 0b0
particularly when matching longer patterns that contain longer sections of literal bits.
~Looks like an oversight, thanks for reporting. I'll look into it.~ The documentation is inaccurate. Since the migration to PPX, single-bit values are interpreted as bool
. The following does work:
let match_bits_with_expected_values _ =
(*
* Create a string of bits.
*)
let bits = Bitstring.bitstring_of_string "a" in
(*
* Match expected bits.
*)
let actual = match%bitstring bits with
| {| false:1 ; true:1 ; _ : -1 : bitstring |} -> true
| {| _ |} -> false
in
assert actual
Thx for the clarification.
(Apols in advance if I'm doing something really dumb)
Have (ppx_)bitstring version 4.1.0 on ocaml 4.11.2
Trying to match a bitstring
bs
with a pattern containing/consisting of a single literal bit fails:(the
{|
appears underlined)In fact, something like the
pattern_matcher
example indocumentation.md
also fails(the
{|
appears underlined)Replacing the literal with a variable works
And then adding a
check
serves as a workaround to get the original intentbut is clunky.