I am attempting to serialize and deserialize a GADT, however, the problem is, I cannot make the type system understand that my deserializer function will return a general GADT.
If the GADT is
type 'a t =
| A : a t
| B : b t
I need a way of expressing that my deserializer function will return any t
depending on the case it falls in
This is all I have tried:
In these cases it complains that the GADT type is inferred as a t
however I am also returning b t
in some cases
let f : ... -> _ t =
| ... -> A
| ... -> B
let f : ... -> 'a t =
| ... -> A
| ... -> B
let f : 'a. ... -> 'a t =
| ... -> A
| ... -> B
In these cases it complains that it expects any t
however I provide it with a t
let f : type any. ... -> any t =
| ... -> A
| ... -> B
let f (type any) ... : any t =
| ... -> A
| ... -> B
I am quite inexperienced with GADTs, and was wondering whether there is a way to express I am returning a GADT of an unknown type yet. Or maybe Iām not understanding how GADTs work.