8TYPE CLASSES
We have seen functions that have a concrete type, such as not, which takes a Bool as input and returns a Bool as output. We have also seen functions with types that use a type variable to express that they work with all types, such as head, which takes a list of any type and returns the first element. Use of a type variable expresses commonality over all types.
Between the extremes of functions that work with a single type and functions that work with all types is a need to express a more limited commonality among types that does not extend to all types. For example, we would like addition to be available for numeric types like ...
Get Learn Physics with Functional Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.