Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Created July 13, 2018 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leonidas-from-XIV/346c9dda7c8d13c16fa6d6194d526dea to your computer and use it in GitHub Desktop.
Save Leonidas-from-XIV/346c9dda7c8d13c16fa6d6194d526dea to your computer and use it in GitHub Desktop.
Looking for a way to handle polymorphic variants
type 'a resp = Handled of unit | Continue of 'a
let handle_x = function Handled () -> Handled () | Continue x -> match x with `X -> Handled () | rest -> Continue rest
let handle_y = function Handled () -> Handled () | Continue x -> match x with `Y -> Handled () | rest -> Continue rest
let handle_xy v = handle_x (handle_y v)
match handle_xy (Continue `X) with
| Handled () -> ()
| Continue v ->
match v with
| `Z -> ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment