In a pure functional language, a Type class is a description of a pattern. Functions can require that their arguments fulfil this pattern, which grants use of the pattern. Data structures can then implement the pattern.
These patterns are available to be constructed in user space. Some of the more common patterns are taken from category theory, such as
Monoids etc, etc.
- Looking for Assumptions in code
- Most languages would stop here - but purescript has Typeclasses. Instead of pulling our pattern out as a Type and having to pass fulfilment functions around, we can declare our pattern as a Typeclass
- PureScript Type Classes
- Traits and Typeclasses
- To the best of my knowledge, the idea of traits in rust is based on the idea of Typeclasses found in Haskell and other pure functional languages. I'm not certain on how they differ, but the idea of stating the equivalent of an interface and then letting data structures implement that interface while wiring up the details under the hood is common.