Programming Languages (CSC-302 98S)
Outline of Class 28: More Haskell Concepts
Held: Friday, April 10, 1998
- Any question on assignment
- Thanks very much to those of you who attended one of the sessions
involving Mr. Earl. The department very much appreciates your comments.
- Did I leave you with an "end of class" question last class? If so,
I've forgotten what it was, but I hope one of you will remind me.
- Haskell is a typeful language. Types play a large role
in the language.
- Programmers are encouraged to define their own types.
- Haskell has a rich type inference and checking system.
- A type declaration gives a type name and a set of
type constuctors which tell how to build objects of that type.
- Constructors may take arguments (e.g., Cons would take two arguments).
- Constructcors may take no arguments (in which case they act like
- Often, there are multiple constructors for a type. These can be separated
with vertical bars.
- For example, an enumerated type would be written something like
data Days = Mon | Tue | Wed | Thu | Fri | Sat | Sun
data Gender = Male | Female | Unspecified
- In a record type, we would also give arguments, as in
data Person = Per String Int Gender
- In this instance,
Per is the constructor, which takes
- A string, perhaps representing the person's name
- An integer, perhaps representing the person's age
- A gender
- Haskell also allows recursive types, such as
data IntList = ILnil | ILcons Int IntList
- More importantly, Haskell allows you to define polymorphic types (what
I've sometimes called metatypes) that take type variables as arguments.
data List a = Nil | Cons a (List a)