3 ms·
I too haven't seen invariance used much, however recently I had a case where my data type (in Haskell) encapsulated both serialization and deserialization from
by afranchuk 8y ago
I too haven't seen invariance used much, however recently I had a case where my data type (in Haskell) encapsulated both serialization and deserialization from a base type, and in this case the only way to "convert" the data type's type parameter was with an invariant transformation. This turned out to be a very elegant way to define a type that could be converted to and from yaml (though both directions were optional), because then the data type also stored the specification of the expected yaml input(s) (since converting to and from other types won't change the original yaml representation).