Regarding finding the number of unique elements in a list.

Hi, I am newbie at Haskell. I am not able to write a program to find the number of unique elments in a list in haskell. I am also not able to write a porgram to find the elements in the innermost list in a list within lists. Can anybody guide me as to g\how to go about it or better still send me the program. It would be of great help. Have a good day.. cheers, amrit. peace....

I consider myself a newbie too but here are my solutions Tom On Fri, 2002-01-18 at 10:14, Amrit K Patil ;012;VKSF6; wrote:
Hi,
I am newbie at Haskell.
I am not able to write a program to find the number of unique elments in a list in haskell.
I am also not able to write a porgram to find the elements in the innermost list in a list within lists.
Can anybody guide me as to g\how to go about it or better still send me the program.
It would be of great help.
Have a good day..
cheers,
amrit.
peace....
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thursday 17 January 2002 03:31 pm, Tom Bevan wrote:
I consider myself a newbie too but here are my solutions
FWIW, at a glance, those are identical, or very similar to, the following standard functions: contains --> elem unique --> nub (you'll need to import List) innerList --> concat --Jeff

"Amrit K Patil ;012;VKSF6;"
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. :-) -kzm -- If I haven't seen further, it is by standing in the footprints of giants
participants (4)
-
Amrit K Patil ;012;VKSF6;
-
Jeffrey R Lewis
-
Ketil's local user
-
Tom Bevan