adam.turoff at gmail.com
Tue Jun 19 15:32:38 EDT 2007
On 6/19/07, Andrew Coppin <andrewcoppin at btinternet.com> wrote:
> However, Haskell only has 1 type of collection: linked lists. (And only
> single-linked at that.) While other "normal" programming languages spend
> huge amounts of effort trying to select exactly the right collection
> type for the task in hand, Haskell programs only ever use linked lists.
Um, not quite.
Lists may be the most common data structure in a Haskell program,
but they certainly aren't the *only* collection type.
A quick tour through the Hierarchical Libraries documentation finds:
- Data.Map (more commonly known as 'dictionaries')
- Data.HashTable (same idea, different runtime characteristics)
- many varieties of Data.Array (fixed sized arrays, with
quick access to any element)
The core language also offers tuples, which are a very interesting
kind of collection, if very primitive. Also, tree structures are trivial
to create that it is often easier to define the precise tree structure
you want instead of reusing one of a dozen possible modules.
Here's one that's common in many tutorials:
data Tree a = Leaf a
| Branch (Tree a) (Tree a)
deriving (Show, Eq)
These are just some of the purely functional data structures
that provide collection types within a Haskell program.
More information about the Haskell-Cafe