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: How to access non-exported function from Data.Set?
(Chadda? Fouch?)
2. Re: How to access non-exported function from Data.Set?
(Ozgur Akgun)
3. Re: How to access non-exported function from Data.Set?
(Chadda? Fouch?)
4. Re: How to access non-exported function from Data.Set?
(Ozgur Akgun)
5. Different ByteStrings, what now? (Raphael P?bst)
6. Re: Different ByteStrings, what now? (Daniel Fischer)
7. Re: Different ByteStrings, what now? (Raphael P?bst)
----------------------------------------------------------------------
Message: 1
Date: Thu, 2 Jun 2011 12:02:42 +0200
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] How to access non-exported function
from Data.Set?
To: Christoph Bussler <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
On Wed, Jun 1, 2011 at 10:56 PM, Christoph Bussler <[email protected]> wrote:
> Hi,
>
>
>
> In Data.Set there is a function splitLookup
>
>
>
> splitLookup :: Ord a => a -> Set a -> (Set a,Maybe a,Set a)
>
>
>
> that is not exported, but would precisely give me the functionality that I
> need. Not sure why it is not exported, but is there a way to use it?
No but splitMember is exported and give you strictly the same
functionality, if you really want to rewrite splitLookup, you can just
do :
> splitLookup x s = let (inf, b, sup) in (inf, if b then Just x else Nothing,
> sup)
--
Jeda?
------------------------------
Message: 2
Date: Thu, 2 Jun 2011 11:03:52 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] How to access non-exported function
from Data.Set?
To: Christoph Bussler <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
You are right, the constructors are not exported so you cannot actually
inline splitLookup.
On 2 June 2011 02:06, Christoph Bussler <[email protected]> wrote:
> In terms of the use case, I?d like to find an element in a set. If the
> element is there, I?d like to get it back (not just the fact that it
> exists). If it is not in the set, I?d like to get the next higher and the
> next lower one (according to the sort order). This is almost exactly what
> splitLookup does, however, splitLookup gives me both the trees, whereas I
> only would need the elements of the set.
But for this use case, you can use splitMember just as well?
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110602/ae6fad59/attachment-0001.htm>
------------------------------
Message: 3
Date: Thu, 2 Jun 2011 12:07:12 +0200
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] How to access non-exported function
from Data.Set?
To: Christoph Bussler <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Jun 2, 2011 at 12:02 PM, Chadda? Fouch?
<[email protected]> wrote:
> No but splitMember is exported and give you strictly the same
> functionality, if you really want to rewrite splitLookup, you can just
> do :
>
>> splitLookup x s = let (inf, b, sup) in (inf, if b then Just x else Nothing,
>> sup)
>
oops, I obviously meant :
> splitLookup x s = let (inf, b, sup) = splitMember x s in (inf, if b then Just
> x else Nothing, sup)
And for what you want :
> yourSplit x s = let (inf, b, sup) = splitMember x s in if b then Right x
> else Left (findMax inf, findMin sup)
--
Jeda?
------------------------------
Message: 4
Date: Thu, 2 Jun 2011 11:18:57 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] How to access non-exported function
from Data.Set?
To: Christoph Bussler <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
I'll give this a try.
On 2 June 2011 02:06, Christoph Bussler <[email protected]> wrote:
> I?d like to find an element in a set. If the element is there, I?d like to
> get it back (not just the fact that it exists). If it is not in the set, I?d
> like to get the next higher and the next lower one (according to the sort
> order).
import Prelude hiding (null)
import Data.Set
-- if the given element is in the set, return it
-- else, try to return the (next lower, next higher)
-- (please ask if you do not understand why I chose this type)
foo :: Ord a => a -> Set a -> Either a (Maybe a, Maybe a)
foo x s = case splitMember x s of
(_, True, _) -> Left x
(low, _, high) -> Right (findMaxMaybe low, findMinMaybe high)
-- *Main> foo 3 $ fromList [1..10]
-- Left 3
--
-- *Main> foo 3 $ fromList [4..10]
-- Right (Nothing,Just 4)
--
-- *Main> foo 3 $ fromList $ 2:[4..10]
-- Right (Just 2,Just 4)
--
-- *Main> foo 3 $ fromList $ []
-- Right (Nothing,Nothing)
findMinMaybe :: Set a -> Maybe a
findMinMaybe s
| null s = Nothing
| otherwise = Just (findMin s)
findMaxMaybe :: Set a -> Maybe a
findMaxMaybe s
| null s = Nothing
| otherwise = Just (findMax s)
HTH,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110602/245bc3d8/attachment-0001.htm>
------------------------------
Message: 5
Date: Thu, 2 Jun 2011 15:23:40 +0200
From: Raphael P?bst <[email protected]>
Subject: [Haskell-beginners] Different ByteStrings, what now?
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hello once again!
My forays into Haskell are once again stopped by my weak Haskell Fu.
I am working with ProtocolBuffers and so far everything worked fine,
but now I have encountered a problem. I am trying to serialize a
message that contains, among other things, a blob of binary data. My
problem now is to get that binary data into the message.
The message requires the data type
Text.ProtocolBuffers.Header.ByteString, whereas my data is of the type
Data.ByteString. How can I turn one into the other or get my data into
the right format in te first place?
I tried to find a function to solve this, but I couldn't find it in
the ProtoBuff documentation.
Thanks
Raf
------------------------------
Message: 6
Date: Thu, 2 Jun 2011 15:30:40 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Different ByteStrings, what now?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Thursday 02 June 2011 15:23:40, Raphael P?bst wrote:
> Hello once again!
> My forays into Haskell are once again stopped by my weak Haskell Fu.
> I am working with ProtocolBuffers and so far everything worked fine,
> but now I have encountered a problem. I am trying to serialize a
> message that contains, among other things, a blob of binary data. My
> problem now is to get that binary data into the message.
> The message requires the data type
> Text.ProtocolBuffers.Header.ByteString, whereas my data is of the type
> Data.ByteString. How can I turn one into the other or get my data into
> the right format in te first place?
> I tried to find a function to solve this, but I couldn't find it in
> the ProtoBuff documentation.
I don't know ProtoBuff, but I suspect that one uses lazy ByteStrings [there
are only lazy and strict ByteStrings in the bytestring package], in which
case you could simply transform your strict ByteString via
strictToLazy bs = Data.ByteString.Lazy.fromChunks [bs]
into a lazy ByteString (the reverse transformation would be
Data.ByteString.concat . Data.ByteString.Lazy.toChunks, but it might be
better to work with lists of strict ByteStrings as delivered by toChunks).
>
> Thanks
>
> Raf
------------------------------
Message: 7
Date: Thu, 2 Jun 2011 15:46:14 +0200
From: Raphael P?bst <[email protected]>
Subject: Re: [Haskell-beginners] Different ByteStrings, what now?
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Ah thanks, that's it. I know about ByteString and ByteString.Lazy, but
the error message confused me, since it said it was expecting
Text.ProtocoelBuffers.Header.ByteString of which I had never heard
before.
Raf
On 6/2/11, Daniel Fischer <[email protected]> wrote:
> On Thursday 02 June 2011 15:23:40, Raphael P?bst wrote:
>> Hello once again!
>> My forays into Haskell are once again stopped by my weak Haskell Fu.
>> I am working with ProtocolBuffers and so far everything worked fine,
>> but now I have encountered a problem. I am trying to serialize a
>> message that contains, among other things, a blob of binary data. My
>> problem now is to get that binary data into the message.
>> The message requires the data type
>> Text.ProtocolBuffers.Header.ByteString, whereas my data is of the type
>> Data.ByteString. How can I turn one into the other or get my data into
>> the right format in te first place?
>> I tried to find a function to solve this, but I couldn't find it in
>> the ProtoBuff documentation.
>
> I don't know ProtoBuff, but I suspect that one uses lazy ByteStrings [there
> are only lazy and strict ByteStrings in the bytestring package], in which
> case you could simply transform your strict ByteString via
>
> strictToLazy bs = Data.ByteString.Lazy.fromChunks [bs]
>
> into a lazy ByteString (the reverse transformation would be
> Data.ByteString.concat . Data.ByteString.Lazy.toChunks, but it might be
> better to work with lists of strict ByteStrings as delivered by toChunks).
>
>>
>> Thanks
>>
>> Raf
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 36, Issue 5
****************************************