[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-cafe
Subject: Re: Regarding finding the number of unique elements in a list.
From: "Ketil's local user" <ketil () ii ! uib ! no>
Date: 2002-01-18 8:10:55
Message-ID: egzo3c9j00.fsf () sefirot ! ii ! uib ! no
[Download RAW message or body]
"Amrit K Patil ;012;VKSF6;" <akp3572@cs.rit.edu> 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. :-)
-kzm
--
If I haven't seen further, it is by standing in the footprints of giants
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic