|
|
|
|
|
by paldepind2
444 days ago
|
|
> I'm not very familiar with these relations, but shouldn't function returns be covariant? `String => Cat` is a subtype of `String => Animal`? You're right :) I mixed up covariance and contravariance for function parameters and return value in my comment. > For function parameters, doesn't it depend on how the parameter is used? I don't think so, but maybe there's specific circumstances I don't know of? Function parameter types is a constraint on _input_ to the function. Changing that to a subtype amounts to the function receiving arguments that satisfies a stronger constraint. That seems that something that would hold no matter how the parameter is used? |
|
> I don't think so, but maybe there's specific circumstances I don't know of?
I don't know specific circumstances either, but I presume they exist because of things like Dart's `covariant` keyword [0], which makes function parameters covariant instead of contravariant.
[0] https://dart.dev/language/type-system#covariant-keyword