-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Description
Map expressions are very helpful, but they lead to "unused-var" warnings which fail builds if not disabled in dune-workspace.
The below raises a warning for editor_status and mode being unused. If I move the map() calls out of the pattern and into normal code (let editor_status = match editor_status with ...), then the warnings go away (as expected).
I'm not sure how to do more debugging.
type mode = GLOBAL | LOCAL
type solution_exa = {
name : string;
code : string;
editor_status : bool;
mode : mode;
image : bool Array.t;
}
let read_exa bits =
match%bitstring bits with
(* EXAs
| Field | Type | Value
---------------------
| Lead-in | byte | 0xA |
| Name | pascal string | two-character name of EXA |
| Source | pascal string | raw code |
| Editor display status | bool byte | false: unrolled, true: collapsed |
| Memory scope | bool byte | false: global, true: local |
| Bitmap | bool byte[100] | Raw bitmap (row-major), true: set pixel |
*)
| {|
0x0A : 8;
len : 32 : littleendian;
name : (Int32.to_int len) * 8 : string;
len : 32 : littleendian;
code : (Int32.to_int len) * 8 : string;
editor_status : 8 : map (fun es -> match es with | 0 -> false | _ -> true);
mode : 8 : map (fun mode -> match mode with | 0 -> GLOBAL | _ -> LOCAL);
bitmap : 800 : bitstring;
rest : -1 : bitstring
|}
->
let data, off, len = bitmap in
let image = Array.make 100 false in
for i = 0 to 99 do
let c = Bitstring.extract_char_unsigned data (off + (i * 8)) len 8 in
Array.set image i (c <> 0)
done;
({ name; code; editor_status; mode; image }, rest)
| {| _ |} -> raise ExitMetadata
Metadata
Assignees
Labels
No labels