Regarding finding the number of unique elements in a list.
Ketil's local user
18 Jan 2002 09:10:55 +0100
"Amrit K Patil ;012;VKSF6;" <firstname.lastname@example.org> writes:
> I am not able to write a program to find the number of unique elments in a
> list in haskell.
Why not? Are you able to find the number of unique elements yourself?
How? I can think of a few ways to do it, for instance
remove all repeated occurences of each letter in turn
sort the list before you count (better time complexity?)
> I am also not able to write a porgram to find the elements in the
> innermost list in a list within lists.
There is a prelude function to concatenate a list of lists, returning
all the elements of the next level as a list. Notice that you can't
really have an "innermost" list in Haskell, since all elements of a
list must be of the same type. E.g. in Lisp you could have
(((a b) (c d) ((e f) g) h) (i j k))
with (e f) as the innermost list. But a list like this is
incompatible with the Haskell type system, and you'd need to declare a
data type something like
data MyList a = Elem a | Nested [MyList a]
or something like that.
> Can anybody guide me as to how to go about it or better still send me
> the program.
Somebody did post a program, but will probably get nasty mail from
your tutor, so I shan't. :-)
If I haven't seen further, it is by standing in the footprints of giants