[Haskell-cafe] Specify array or list size?

Daniel Carrera dcarrera at digitaldistribution.com
Sat May 7 12:04:30 EDT 2005


Hamilton Richards wrote:

> Well, for starters, lists and arrays are two entirely different topics. 
> I've noticed that Haskell newbies sometimes confuse them --possibly the 
> use of [] in list types and enumerations triggers an unconscious 
> association with [] used in conventional languages for array indexing.

I think it's because there's no real reason for someone to think that 
the words "list" and "array" might not be synonims. I certainly don't 
seen a linguistic distinction. Either term refers to an ordered 
collection of items.

Suppose that you learn a new computer language, and it happens to assign 
special meanings to the words "collection" and "group". You don't know 
this. So you start talking about groups as you do in every day English 
and people tell you that you're mixing up concepts.

I guess that a more likely example in programming would be a language 
that differentiates between "functions", "procedures" and "subroutines".

> As for Haskell arrays, I've been programming in Haskell since the early 
> 1990's, and I've never really needed them. Most Haskell programmers find 
> lists much more useful, and you'd probably be better off concentrating 
> on lists until you encounter a problem in which arrays are really 
> needed.

Arrays have O(1) lookup, and Lists have O(n) lookup. For some purposes, 
arrays might be better. I'm thinking of reimplementing RC4 with arrays 
to see if it makes a differece.

> When you do, you'll discover that in Haskell as in most other 
> languages, an array's size is not part of its type.

Well... that's not quite what I was looking for. I just wanted to raise 
an error if the array ever has length other than 256. And I don't know 
how to do that on a language that doesn't have side-effects.

> It's nice to see you taking up Haskell with such enthusiasm. If you 
> agree with many of us that Haskell's one of today's best programming 
> programming languages, I hope you'll help spread the word.

:-)

A lot of concepts from Haskell match the way I think about problems. You 
see, my background is in math, not programming. For example, currying 
and higher order functions are essentially new names for things I've 
been doing for years. So after the concept was explained to me, it 
didn't take me that long to "get it".

My current impression is that Haskell is great for anyone with good 
mathematics education. But I don't know how it'd fare with other people.

I have a lady friend who wants to learn how to program. She's a 
technical person, but has no math background to speak of. I can't decide 
whether to start with a clear-syntax imperative language (Ruby) or a 
functional language (Haskell). I confess I've been leaning towards Ruby.

Cheers,
Daniel.


More information about the Haskell-Cafe mailing list