What is the difference between traits in Rust and typeclasses in Haskell?

前端 未结 3 883
旧时难觅i
旧时难觅i 2020-12-12 12:15

Traits in Rust seem at least superficially similar to typeclasses in Haskell, however I\'ve seen people write that there are some differences between them. I was wondering e

3条回答
  •  一整个雨季
    2020-12-12 12:49

    Rust's “traits” are analogous to Haskell's type classes.

    The main difference with Haskell is that traits only intervene for expressions with dot notation, i.e. of the form a.foo(b).

    Haskell type classes extend to higher-order types. Rust traits only don't support higher order types because they are missing from the whole language, i.e. it's not a philosophical difference between traits and type classes

提交回复
热议问题