You might be interested also in the Flags module in Core_kernel, which aims to serve a similar purpose. https://ocaml.janestreet.com/ocaml-core/111.03.00/doc/core_kernel/#Flags https://github.com/janestreet/core_kernel/blob/master/lib/flags.ml https://github.com/janestreet/core_kernel/blob/master/lib/flags.mli https://github.com/janestreet/core_kernel/blob/master/lib/flags_intf.ml y On Wed, Mar 19, 2014 at 8:01 AM, David Allsopp wrote: > Firstly, many thanks for the various replies to my earlier request for > pointers and guidance on packaging earlier this month. > > I'm pleased to announce the release of BitMasks 1.0.0. This library is > designed primarily with C bindings in mind and is yet another solution to > the "how do we manipulate integer bitmask flags functionally" problem. So, > given an integer where bit 0 means something, bit 1 means something else > and > bit 2 yet something further, this library allows that to be exposed as type > t = Foo | Bar | Baz and have the integer be constructed as though it were a > set. > > This implementation has three key features: > * Underlying type is provided through a functor (so int or int64 or indeed > an arbitrary precision integer can be used) > * There's no copying, so the original integer can still be used (either > internally or, at the whim of the programmer, the integer can be exposed). > This has significant advantages over, for example, returning the a list of > the bits which are set. > * The resulting signature is compatible with Set.S in the standard library > > Project home: http://forge.ocamlcore.org/projects/bitmasks/ > Repository: https://github.com/meta-stack/bitmasks > OPAM package: bitmasks > > The source includes a full example. I believe having looked at other code > out there that Core follows a similar philosophy. > > The original motivation for this library was to provide a sane handling for > the myriad masks of information returned by ODBC's SQLGetInfo function, but > I've found it be useful in other bindings as well (particularly for > bindings > for some Raspberry Pi components which I hope to release soon) and hope > others may do too. > > Happy functional bit set manipulating! > > > David > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >