rescript-lang.org icon indicating copy to clipboard operation
rescript-lang.org copied to clipboard

Document co / contravariance (`<+a>`, `<-a>`)

Open ryyppy opened this issue 4 years ago • 3 comments

This one is definitely an advanced topic.

  • What does + and - mean?
  • What syntax constructs are possible? (type, function, etc.)
  • What practical use-cases does it have / Why do we need it?

Things to avoid:

  • Complex / too scientific wording
  • Too generic examples without practical context

Hints:

  • We use a covariant type in Js.Promise.t (see it here)

ryyppy avatar Jan 01 '21 10:01 ryyppy

Probably also related to subtyping (#150)

ryyppy avatar Jan 01 '21 11:01 ryyppy

I found that the tour of scala has a great introduction to variance: https://docs.scala-lang.org/tour/variances.html

tom-sherman avatar May 18 '21 17:05 tom-sherman

Flow documentation also has good examples https://flow.org/en/docs/lang/variance/

imagen imagen

aganoza avatar May 18 '21 18:05 aganoza