[Haskell] Litle problem with a haskell Function...
Ben Rudiak-Gould
Benjamin.Rudiak-Gould at cl.cam.ac.uk
Wed Nov 3 06:49:29 EST 2004
Manuel Costa wrote:
> I need to do
> add "c"
>
> and the "c" most be append to list1
> to make list1=["a","c"]
>
> Then if i input
> list1
> the output must be
> ["a","c"]
>
> But i can't do it...
It can't be done. Your source code defines list1 to be equal to "a", and
so equal to "a" it is. It can't also be equal to something else.
There is a language feature that would give you something similar to
what you're asking for, but I'm not going to mention it because I'm 99%
sure it's not what you really want here, and it would just lead you down
the wrong path.
In general you need to explicitly pass around everything that you want
to "change" -- for example, you could write your add function like this:
add x list = list ++ [x]
and then every time you call it, use the list it returns from then on
instead of the list you passed to it.
-- Ben
More information about the Haskell
mailing list