[Haskell-beginners] How to access non-exported function from Data.Set?

Christoph Bussler chbussler at aol.com
Thu Jun 2 03:06:38 CEST 2011

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 Bussler
ChBussler at aol.com


From: Ozgur Akgun [mailto:ozgurakgun at gmail.com] 
Sent: Wednesday, June 01, 2011 3:25 PM
To: Christoph Bussler
Cc: beginners at haskell.org
Subject: Re: [Haskell-beginners] How to access non-exported function from


Hi Christoph,

On 1 June 2011 21:56, Christoph Bussler <chbussler at aol.com> 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:


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.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110601/f9c8b44e/attachment.htm>

More information about the Beginners mailing list