How to access non-exported function from Data.Set?

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? Thanks, Christoph -------------------------------------------------------------------------- Christoph Bussler ChBussler@aol.com www.real-programmer.com www.linkedin.com/in/chbussler www.google.com/search?hl=en&q=Christoph+Bussler www.google.com/search?hl=en&q=Christoph%20Bussler&btnI=I%27m+Feeling+Lucky --------------------------------------------------------------------------

Hi Christoph,
On 1 June 2011 21:56, Christoph Bussler
splitLookup :: Ord a => a -> Set a -> (Set a,Maybe a,Set a)
Not sure why it is not exported, but is there a way to use it?
I am afraid you'll have to define the exact same function yourself, if you really want to use it. As you probably already know, you can copy it from: http://hackage.haskell.org/packages/archive/containers/0.4.0.0/doc/html/src/... I am not sure as to why it was not exported though. If you describe your use case, maybe you can convince people to make a change, or people can suggest you some other function which fulfils your requirements in some other way. HTH, Ozgur

Hi,
Thanks; so I imported Data.Set and copied the function
splitLookup :: Ord a => a -> Set a -> (Set a,Maybe a,Set a)
splitLookup _ Tip = (Tip,Nothing,Tip)
splitLookup x (Bin _ y l r)
= case compare x y of
LT -> let (lt,found,gt) = splitLookup x l in (lt,found,join y gt r)
GT -> let (lt,found,gt) = splitLookup x r in (join y l lt,found,gt)
EQ -> (l,Just y,r)
When compiling it says:
src\Main.hs:70:15: Not in scope: data constructor `Tip'
src\Main.hs:70:22: Not in scope: data constructor `Tip'
src\Main.hs:70:34: Not in scope: data constructor `Tip'
src\Main.hs:71:16: Not in scope: data constructor `Bin'
src\Main.hs:73:63: Not in scope: `join'
src\Main.hs:74:54: Not in scope: `join'
And I think this makes sense as neither the data constructors, nor the
function 'join' are exported. Is there any other way you could think of?
In terms of the maintainers of the containers or Data.Set, how do I find out
who could make a decision to include splitLookup in the export list?
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.
Thanks a lot!
Christoph
--------------------------------------------------------------------------
Christoph Bussler
ChBussler@aol.com
www.real-programmer.com
www.linkedin.com/in/chbussler
www.google.com/search?hl=en&q=Christoph+Bussler
www.google.com/search?hl=en&q=Christoph%20Bussler&btnI=I%27m+Feeling+Lucky
--------------------------------------------------------------------------
_____
From: Ozgur Akgun [mailto:ozgurakgun@gmail.com]
Sent: Wednesday, June 01, 2011 3:25 PM
To: Christoph Bussler
Cc: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to access non-exported function from
Data.Set?
Hi Christoph,
On 1 June 2011 21:56, Christoph Bussler

I've run into this with other modules although I can't think of any
specific examples off the top of my head.
I think if would be a great language feature if modules had three
levels of exported functions and datatypes,
1. normally API functions that are available using the usual "import
Some.Module"
2. functions that must be imported specifically because they are not
recommended for general use by maybe useful like the OP's example.
This functionality could just piggyback on the existing explicit
import syntax, eg. "import Some.Module (someSemiPrivateFunction).
3. Functions or datatypes that are not exported at all.
-deech
On Wed, Jun 1, 2011 at 8:06 PM, Christoph Bussler
Hi,
Thanks; so I imported Data.Set and copied the function
splitLookup :: Ord a => a -> Set a -> (Set a,Maybe a,Set a)
splitLookup _ Tip = (Tip,Nothing,Tip)
splitLookup x (Bin _ y l r)
= case compare x y of
LT -> let (lt,found,gt) = splitLookup x l in (lt,found,join y gt r)
GT -> let (lt,found,gt) = splitLookup x r in (join y l lt,found,gt)
EQ -> (l,Just y,r)
When compiling it says:
src\Main.hs:70:15: Not in scope: data constructor `Tip'
src\Main.hs:70:22: Not in scope: data constructor `Tip'
src\Main.hs:70:34: Not in scope: data constructor `Tip'
src\Main.hs:71:16: Not in scope: data constructor `Bin'
src\Main.hs:73:63: Not in scope: `join'
src\Main.hs:74:54: Not in scope: `join'
And I think this makes sense as neither the data constructors, nor the function ‘join’ are exported. Is there any other way you could think of?
In terms of the maintainers of the containers or Data.Set, how do I find out who could make a decision to include splitLookup in the export list?
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.
Thanks a lot!
Christoph
-------------------------------------------------------------------------- Christoph Bussler ChBussler@aol.com www.real-programmer.com www.linkedin.com/in/chbussler www.google.com/search?hl=en&q=Christoph+Bussler www.google.com/search?hl=en&q=Christoph%20Bussler&btnI=I%27m+Feeling+Lucky --------------------------------------------------------------------------
________________________________
From: Ozgur Akgun [mailto:ozgurakgun@gmail.com] Sent: Wednesday, June 01, 2011 3:25 PM To: Christoph Bussler Cc: beginners@haskell.org Subject: Re: [Haskell-beginners] How to access non-exported function from Data.Set?
Hi Christoph,
On 1 June 2011 21:56, Christoph Bussler
wrote: splitLookup :: Ord a => a -> Set a -> (Set a,Maybe a,Set a)
Not sure why it is not exported, but is there a way to use it?
I am afraid you'll have to define the exact same function yourself, if you really want to use it. As you probably already know, you can copy it from: http://hackage.haskell.org/packages/archive/containers/0.4.0.0/doc/html/src/...
I am not sure as to why it was not exported though. If you describe your use case, maybe you can convince people to make a change, or people can suggest you some other function which fulfils your requirements in some other way.
HTH,
Ozgur
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

You are right, the constructors are not exported so you cannot actually
inline splitLookup.
On 2 June 2011 02:06, Christoph Bussler
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

I'll give this a try.
On 2 June 2011 02:06, Christoph Bussler
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

On Wed, Jun 1, 2011 at 10:56 PM, Christoph Bussler
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ï

On Thu, Jun 2, 2011 at 12:02 PM, Chaddaï Fouché
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ï
participants (4)
-
aditya siram
-
Chaddaï Fouché
-
Christoph Bussler
-
Ozgur Akgun