Next: Map and Filter
Up: The Frightened Freshers Guide
Previous: Polymorphic Functions
Note that the ListInt and List datatypes that have been defined earlier on in this set of pages can be used, although it is far easier and shorter to write out lists using the shorthand in square brackets. The first line of the old style first defines a list type using the algebraic data type, the second line is the list itself. The two other examples are both examples of the built in polymorphic list type; The first one is a list of Strings and the second a list of Ints.
When it comes to patten matching on lists like this, it is fairly simple:
Note that the haskell prelude already has a function a little bit like this for finding the number of elements in a list simply called length:
Tom Carlson
2006-04-11