Value.MatchRuntime parallel match.
This module can be used to handle several cases in parallel instead of using a sequence of nested matches or if/then/else chains.
The combinators in the module are designed to be used as follows:
let lift v = Match.(begin
switch v @@
case memory_load (fun x -> `Load x) @@
case memory_store (fun x -> `Store x) @@
case register_read (fun x -> `Read x) @@
default (fun () -> `Unknown)
end)Note: in the example, the whole expression will build and then match. In case when performance matter, and when there is more then one match, it is recommended to evaluate a matching object first, and return a function, that matches values. For this there is a select combinator:
let lift =
Match.(begin
select @@
case memory_load (fun x -> `Load x) @@
case memory_store (fun x -> `Store x) @@
case register_read (fun x -> `Read x) @@
default (fun () -> `Unknown)
end)select matcher x applies matcher to value x. select is the same as Fn.flip switch.
case tag action matcher adds an action to matcher that will be invoked for values with a a given tag
val default : (unit -> 's) -> 's tdefault def creates an empty matcher with default handler def.