Regarding finding the number of unique elements in a list.
Tom Bevan
tom@regex.com.au
18 Jan 2002 10:31:17 +1100
--=-gqkGX1d7Wuy/j1GdRvIE
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
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
--=-gqkGX1d7Wuy/j1GdRvIE
Content-Disposition: attachment; filename=unique.hs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
--Function that returns true if
--an element in contained in the list
contains :: Eq a =3D> a -> [a] -> Bool
contains _ [] =3D False
contains a (x:xs) | a=3D=3Dx =3D True
| otherwise =3D contains a xs
--Function to remove all multiple
--occurences of elements in a list
unique :: Eq a =3D> [a] -> [a]
unique [] =3D []
unique (x:xs) | contains x xs =3D unique xs
| otherwise =3D x:unique xs
innerList :: [[a]] -> [a]
innerList =3D foldr (++) []
--=-gqkGX1d7Wuy/j1GdRvIE--