[Haskell-beginners] Beginners Digest, Vol 45, Issue 35

Lorenzo Bolla lbolla at gmail.com
Wed Mar 28 16:33:45 CEST 2012


Or, with a one-liner (inefficient, though):

unique xs = [x | x <- xs, length (filter (== x) xs) == 1]

L.


On Wed, Mar 28, 2012 at 9:38 AM, <franco00 at gmx.com> wrote:

>
> Indeed the second snipper contains quite an obvious mistake. Thanks for
> noticing!
>
> It doesn't seem to me it utilises a lambda expression though? You mean the
> '.' operator for chaining function? If that's it, it could be rewritten
>
>
> unique :: [Integer] -> [Integer]
> unique []   = []
> unique (x:xs) | elem x xs   = unique (filter (/= x) xs)
>
>               | otherwise   = x : unique xs
>
>
>
>
>
>
>
>
>  ----- Original Message -----
>
> From: Ramesh Kumar
>
> Sent: 03/28/12 10:14 AM
>
> To: franco00 at gmx.com, beginners at haskell.org
>
> Subject: Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
>
>   Thanks Franco, Your (first) solution is the only one which has worked
> so far although it utilizes a lambda expression.
>  The problem is indeed tricky.
>
>
>
>   ------------------------------
> *From:* "franco00 at gmx.com" <franco00 at gmx.com>
> *To:* beginners at haskell.org
> *Sent:* Wednesday, March 28, 2012 3:39 PM
> *Subject:* Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
>
>  gah sorry I obviously meant to reply to the "Unique integers in a list"
> message
>
>
>
>
>
>  ----- Original Message -----
>  From: franco00 at gmx.com
>  Sent: 03/28/12 09:36 AM
>  To: beginners at haskell.org
>  Subject: Re: Beginners Digest, Vol 45, Issue 35
>
>  unique :: [Integer] -> [Integer]
> unique []   = []
> unique (x:xs) | elem x xs   = (unique . filter (/= x)) xs
>               | otherwise   = x : unique xs
>
> -- This is a simpler to read version (albeit inefficient?)
> unique :: [Integer] -> [Integer]
> unique []   = []
> unique (x:xs) | elem x xs   = unique xs
>               | otherwise   = x : unique xs
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120328/46123106/attachment.htm>


More information about the Beginners mailing list