Reputation: 99428
In Haskell programming language, according to https://en.wikibooks.org/wiki/Haskell/Category_theory#Translating_categorical_concepts_into_Haskell
59.2.2 Translating categorical concepts into Haskell
We work in the category
Hask
and its subcategories.Objects are types.
Morphisms are functions.
Things that take a type and return another type are type constructors.
Things that take a function and return another function are higher-order functions.
Typeclasses, along with the polymorphism they provide, make a nice way of capturing the fact that in category theory things are often defined over a number of objects at once.
What concept in category theory is a typeclass represented as? As a subcategory of Hask
?
Upvotes: 5
Views: 542
Reputation: 11630
According to Dominic Orchard, typeclasses correspond to subcategories of Hask:
The instances of a single parameter type class can be interpreted as describing the members of a set of types (or a relation on types for multi-parameter type classes). In a type signature, a universally quantified type variable constrained by a type class constraint represents a collection of types that are members of the class. E.g. for the
Eq
class, the following type signature describes a collection of types for which there are instances ofEq
:Eq a => a
The members of
Eq
are a subcollection of the objects of Hask. Similarly, the type:(Eq a, Eq b) => (a -> b)
represents a subcollection of the morphisms of Hask mapping between objects in the subcollection of objects which are members of
Eq
. Thus, theEq
class defines anEq
-subcategory of Hask with the above subcollections of objects and morphisms.
Upvotes: 8