Yes, I understand your intention.
I have my own MessagePack decoder for TypeScript written in ReScript.
And there is result
instead of Obj.repr
, but it is never used for value
type. Because they have different semantics and different sources.
The conversion to the top type is safe, but other codes that receive that type must handle it structurally.
That is not healthy from a language perspective, but it is allowed for FFIs.
If your decoder doesn’t allow partial errors, the value
type should be the same as the input. Suppose you used Result instead of an exception. The decoder already knows the input type 'a
, so it shouldn’t need to coerce at all.
Then the compiler’s approach is to improve the type inferences on exceptions.