Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Unique integers in a list (KC)
2. Re: Beginners Digest, Vol 45, Issue 35 ([email protected])
3. Re: Beginners Digest, Vol 45, Issue 35 ([email protected])
4. Re: Beginners Digest, Vol 45, Issue 35 (Ramesh Kumar)
5. Re: Beginners Digest, Vol 45, Issue 35 ([email protected])
----------------------------------------------------------------------
Message: 1
Date: Wed, 28 Mar 2012 00:29:18 -0700
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] Unique integers in a list
To: Ramesh Kumar <[email protected]>,
[email protected]
Message-ID:
<CAMLKXykNY81n9+_ZRHa2Ox=nvnz7erhw9hfff4r5vaa5aso...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Sort then ...
On Tue, Mar 27, 2012 at 7:03 PM, Ramesh Kumar <
[email protected]> wrote:
> Hi,
>
> I've just started learning Haskell a couple of weeks ago using Simon
> Thompson's "Haskell: Craft of Functional Programming".
> There is an exercise in chapter 7 of the book which goes something like
> this:
>
> Define a function of the type: unique :: [Integer] -> [Integer]
> which if given a list of integers, should return a list of those integers
> which occur only once in the input list.
> Example:
> unique [5,2,4,2,3,1,5,2] should result in [4,3,1]
>
>
> *** The questions assumes we know only of list comprehensions and
> recursion.
>
> I am guessing the solution must include something like this:
>
> unique :: [Integer] -> [Integer]
> unique xs = [ x | x <- xs, isSingle x ]
>
> My problem is in defining the function 'isSingle'.
>
> I would greatly appreciate any pointers on this.
>
> Many thanks.
> Ramesh
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
--
Regards,
KC
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120328/c78d488e/attachment-0001.htm>
------------------------------
Message: 2
Date: Wed, 28 Mar 2012 09:36:33 +0200
From: [email protected]
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120328/2ada60ea/attachment-0001.htm>
------------------------------
Message: 3
Date: Wed, 28 Mar 2012 09:39:15 +0200
From: [email protected]
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
gah sorry I obviously meant to reply to the "Unique integers in a list" message
----- Original Message -----
From: [email protected]
Sent: 03/28/12 09:36 AM
To: [email protected]
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120328/377a7882/attachment-0001.htm>
------------------------------
Message: 4
Date: Wed, 28 Mar 2012 01:14:24 -0700 (PDT)
From: Ramesh Kumar <[email protected]>
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
To: "[email protected]" <[email protected]>, "[email protected]"
<[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
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: "[email protected]" <[email protected]>
>To: [email protected]
>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: [email protected]
>>Sent: 03/28/12 09:36 AM
>>To: [email protected]
>>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
>[email protected]
>http://www.haskell.org/mailman/listinfo/beginners
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120328/a9dded99/attachment-0001.htm>
------------------------------
Message: 5
Date: Wed, 28 Mar 2012 10:38:26 +0200
From: [email protected]
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
To: "Ramesh Kumar"
<[email protected]>,[email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
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: [email protected], [email protected]
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: "[email protected]" <[email protected]>
To: [email protected]
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: [email protected]
Sent: 03/28/12 09:36 AM
To: [email protected]
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
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120328/598cb767/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 45, Issue 36
*****************************************