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

aditya siram aditya.siram at gmail.com
Thu Jun 2 03:18:23 CEST 2011


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 <chbussler at aol.com> wrote:
> 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 at 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 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
> Data.Set?
>
>
>
> 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: http://hackage.haskell.org/packages/archive/containers/0.4.0.0/doc/html/src/Data-Set.html#splitLookup
>
>
>
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



More information about the Beginners mailing list