(no title)
paldepind2 | 11 months ago
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?
pansa2|11 months ago
> 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
sparkie|11 months ago
Consider if we have `A <= B <= C`, and a function:
Given some potential inputs: The following should be true: If the `dest` argument were contravariant, it would permit invalid copies and forbid valid ones. In a purely functional setting, you should not need a covariant parameter type because all writes would end up in the return type.kragen|11 months ago
hmry|11 months ago