A relatively recent edition to the language (I can’t seem to find which version) is locally abstract types in pattern matching.
This looks something like:
type _ spec =
| Int : int spec
| String : string spec
type t0 = T0 : 'a spec * 'a -> t0
let f0 = function
| T0 (type a) ((spec, v) : a spec * a) -> ()
Is it possible to use this syntax/feature with inline record arguments? The following doesn’t work:
type t1 = T1 : { spec : 'a spec; value : 'a } -> t1
let f1 = function
| T1 (type a) { spec : a spec; value : a } -> ()
Error: Existential types introduced in a constructor pattern
must be bound by a type constraint on the argument.
I recognize that the first example also doesn’t work if you annotate the individual elements of the tuple, but there’s no separate type I can reference here.
I could obviously separate out the record into its own type and annotate t1
with [@@unboxed]
, but was curious if it was possible without doing this.