Next | Atypical Types | 33 |
Type classes are something like object classes in Java
Several different types might be instances of the same class
This means they must support some basic set of operations
For example, any type t might be an instance of the Show class
If so, there must be a function show of type t -> String
The Haskell standard library makes all the standard types instances of Show
So for example:
show 137 yields "137" show True yields "True" show "Foo" yields "\"Foo\""
If you define your own type, you can define a show method
And you can declare your type to be an instance of Show
Notation:
Show Integer ("Integer is an instance of Show") Show Bool ("Bool is an instance of Show") Show [Char] ("[Char] is an instance of Show")
Next | Copyright © 1999,2008 Mark Dominus |