[Haskell-cafe] Emptying a list

Sebastian Sylvan sebastian.sylvan at gmail.com
Sat Oct 15 05:51:39 EDT 2005

On 10/15/05, poogle at netspace.net.au <poogle at netspace.net.au> wrote:
> Before you read any more, let me just say I'm fairly new to Haskell, so forgive
> me if this is really basic stuff.
> Hi there, I'm just wondering if there is a command for emptying a list?

Variables in haskell do not vary.
So there's not even way to add an element to a list, but there is an
operator which will construct a NEW list by adding an element to the
front of an EXISTING list: xs' = 'a' : xs
xs' is xs but with an 'a' in front. Note that you can still access the
old list xs, you never update the meaning of the variable xs, you
merely create a new variable (with a new value) called xs'.

So. To answer you question, no you can not change the meaning of a
variable which contains a list, into all of a sudden containing the
empty list.
You can however use the value of the empty list, which is simply: []

> Also, is there any way to incorporate list operations (concatenation in
> particular) in a do-statement on lists? Every time I try it gives a type error.

Not quite sure what you mean. Perhaps an example of what you'd want to


Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list