- This type is parameterized by \hs{a}, which can contain any type at
- all. This means that \hs{append} can append an element to a vector,
- regardless of the type of the elements in the list (as long as the type of
- the value to be added is of the same type as the values in the vector).
- This kind of polymorphism is extremely useful in hardware designs to make
- operations work on a vector without knowing exactly what elements are
- inside, routing signals without knowing exactly what kinds of signals
- these are, or working with a vector without knowing exactly how long it
- is. Polymorphism also plays an important role in most higher order
- functions, as we will see in the next section.
-
- Another type of polymorphism is \emph{ad-hoc
- polymorphism}~\cite{polymorphism}, which refers to polymorphic
- functions which can be applied to arguments of different types, but which
- behave differently depending on the type of the argument to which they are
- applied. In Haskell, ad-hoc polymorphism is achieved through the use of
- type classes, where a class definition provides the general interface of a
- function, and class instances define the functionality for the specific
- types. An example of such a type class is the \hs{Num} class, which
- contains all of Haskell's numerical operations. A designer can make use
- of this ad-hoc polymorphism by adding a constraint to a parametrically
- polymorphic type variable. Such a constraint indicates that the type
- variable can only be instantiated to a type whose members supports the
- overloaded functions associated with the type class.
+ This type is parameterized in \hs{a} and \hs{b}, which can both
+ represent any type at all (as long as that type is supported by the
+ \CLaSH\ compiler). This means that \hs{first} works for any tuple,
+ regardless of what elements it contains. This kind of polymorphism is
+ extremely useful in hardware designs, for example when routing signals
+ without knowing their exact type, or specifying vector operations that
+ work on vectors of any length and element type. Polymorphism also plays an
+ important role in most higher order functions, as will be shown in the
+ next section.
+
+ % Another type of polymorphism is \emph{ad-hoc
+ % polymorphism}~\cite{polymorphism}, which refers to polymorphic
+ % functions which can be applied to arguments of different types, but
+ % which behave differently depending on the type of the argument to which
+ % they are applied. In Haskell, ad-hoc polymorphism is achieved through
+ % the use of \emph{type classes}, where a class definition provides the
+ % general interface of a function, and class \emph{instances} define the
+ % functionality for the specific types. An example of such a type class is
+ % the \hs{Num} class, which contains all of Haskell's numerical
+ % operations. A designer can make use of this ad-hoc polymorphism by
+ % adding a \emph{constraint} to a parametrically polymorphic type
+ % variable. Such a constraint indicates that the type variable can only be
+ % instantiated to a type whose members supports the overloaded functions
+ % associated with the type class.
+
+ Another type of polymorphism is \emph{ad-hoc polymorphism}, which refers
+ to function that can be applied to arguments of a limited set to types.
+ Furthermore, how such functions work may depend on the type of their
+ arguments. For example, addition only works for numeric types, and it
+ works differently for e.g. integers and complex numbers.
+
+ In Haskell, ad-hoc polymorphism is achieved through the use of \emph{type
+ classes}, where a class definition provides the general interface of a
+ function, and class \emph{instances} define the functionality for the
+ specific types. For example, all numeric operators are gathered in the
+ \hs{Num} class, so every type that wants to use those operators must be
+ made an instance of \hs{Num}.
+
+ By prefixing a type signature with class constraints, the constrained type
+ parameters are forced to belong to that type class. For example, the
+ arguments of the \hs{add} function must belong to the \hs{Num} type class
+ because the \hs{add} function adds them with the (+) operator: