reset password
Author Message
rabbott
Posts: 1649
Posted 12:18 Feb 03, 2019 |

In his video on Types, Drake (surprisingly) says that Types are sets of values and Type Classes are sets of Types. 

That's an over-simplification -- to the point of being wrong. (Lipovača doesn't say this.)

For example, the type of the head function is: head :: [a] -> a

[a] -> a is a type, but it is not a collection of values. There are an infinite number of functions with that same type. The type is not defined as the collection of those functions.

Similarly, Integer is the type of all the integer values that an implementation of Haskell can represent on a given machine. But it is not defined specifically from one computer to another as a specific set of integer values, which differs from one implementation to another. Even the type Int is not defined as a specific set of values. It is the set of integers that can be represented in a single, say, 32 bit word. But in another implementation it may correspond to integer values that can be represented in 16 bits or 64 bits. 

In the olden days of computing, int, float, double, and char were defined as sets of values. But now, types have a more independent existence. As you probably know, an abstract data type is defined as a set of operations. That's the best way to think of a type--as a set of operations that can be performed on objects of that type.

Similarly, Type Classes are not sets of Types. They are what Python now calls protocols or structural types, which is a fancier way of saying duck types. (See PEP 544.) A Haskell Type Class is a collection of operations that a Type must implement to be considered a member of that Type Class. In Java terms, a Type Class is an Interface.
A discussion to this effect has been added at the end of this week's assignment.

 

Last edited by rabbott at 12:19 Feb 03, 2019.