On 07/21/2012 05:55 AM, ikarus wrote:
> type variant = GoodRecord of record | EmptyRecord
btw, the option type already encapsulates this pattern.
type 'a option = Some of 'a | None
> Now I'm just find myself creating a record in GoodRecord constructor in
> pattern matching branch, but for big structures (>10 fields) it seems to
> be a lot of code duplication (and code looks a little bit silly):
> -> GoodRecrod {a = a; b = b; ...(* many rows to come *) }
With OCaml 3.12, you can do {a; b; c; ...} to create a record from
values bound to identifiers that match the record field names.
Other than this, it might be possible to modify bitstring to support
bittype records, maybe something like:
bittype record = {a: 16; d:1; ...}
Where the actual record fields are typed as bitstring would type matches
of those sizes. Then you could use something like:
bitmatch bits with
| { r: record } -> Some r
| { _ } -> None
E.