hackwaly / blog

我的博客
8 stars 0 forks source link

Trait object is a poor design #9

Open hackwaly opened 7 months ago

hackwaly commented 7 months ago

Existential type is better. Trait object just complex the semantics.

Existential type can achieve trait object.

struct TraitObj {
  type T : TraitA
  value : T
}

And something hard to achieve if there's only trait object

struct ReactElement {
  type Props 
  props : Props
  type_ : ComponentType<Props>
}