Data.List.join

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
84 messages Options
12345
Reply | Threaded
Open this post in threaded view
|

Data.List.join

Josef Svenningsson
Hi,

I'd like to propose to include the following function in Data.List:
join :: [a] -> [[a]] -> [a]
join x xs = concat (intersperse x xs)

I find that every time I use intersperse I also concat the result. And
it seems that I'm not alone:
http://www.google.com/codesearch?q=file%3A%5C.hs+intersperse&btnG=Search+Code
A clear majority of all the uses of intersperse also use concat on the
result. I think it seems worthwhile to give a name to that idiom.

The name 'join' was taken from Data.ByteString, where a similar function exists.

All the best,

Josef Svenningsson
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Donald Bruce Stewart
josef.svenningsson:

> Hi,
>
> I'd like to propose to include the following function in Data.List:
> join :: [a] -> [[a]] -> [a]
> join x xs = concat (intersperse x xs)
>
> I find that every time I use intersperse I also concat the result. And
> it seems that I'm not alone:
> http://www.google.com/codesearch?q=file%3A%5C.hs+intersperse&btnG=Search+Code
> A clear majority of all the uses of intersperse also use concat on the
> result. I think it seems worthwhile to give a name to that idiom.

Oh, that's a nice trick for working out apis. Good idea!

>
> The name 'join' was taken from Data.ByteString, where a similar function
> exists.

Seems reasonable.  Want to submit a darcs patch, and maybe a quickcheck
property or two?

-- Don
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Samuel Bronson
On 10/21/06, Donald Bruce Stewart <[hidden email]> wrote:
> josef.svenningsson:

> > The name 'join' was taken from Data.ByteString, where a similar function
> > exists.
>
> Seems reasonable.  Want to submit a darcs patch, and maybe a quickcheck
> property or two?

But wait! There is also a join in Control.Monad!
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Josef Svenningsson
In reply to this post by Donald Bruce Stewart
On 10/21/06, Donald Bruce Stewart <[hidden email]> wrote:
> josef.svenningsson:
> > I find that every time I use intersperse I also concat the result. And
> > it seems that I'm not alone:
> > http://www.google.com/codesearch?q=file%3A%5C.hs+intersperse&btnG=Search+Code
> > A clear majority of all the uses of intersperse also use concat on the
> > result. I think it seems worthwhile to give a name to that idiom.
>
> Oh, that's a nice trick for working out apis. Good idea!
>
Thanks!

> > The name 'join' was taken from Data.ByteString, where a similar function
> > exists.
>
> Seems reasonable.  Want to submit a darcs patch, and maybe a quickcheck
> property or two?
>
Well, I do have commit rights myself so I can apply whatever we agree
on. Or did you mean that it would be nice with some public scrutiny of
the patch?

Where would the quickcheck properties go, btw?

Cheers,

Josef
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Josef Svenningsson
In reply to this post by Samuel Bronson
On 10/21/06, Samuel Bronson <[hidden email]> wrote:

> On 10/21/06, Donald Bruce Stewart <[hidden email]> wrote:
> > josef.svenningsson:
>
> > > The name 'join' was taken from Data.ByteString, where a similar function
> > > exists.
> >
> > Seems reasonable.  Want to submit a darcs patch, and maybe a quickcheck
> > property or two?
>
> But wait! There is also a join in Control.Monad!
>
Good point. But I don't really see that as a problem. Don't you think
the two 'join's can co-exist?

It's just that I happen to like 'join' very much. But perhaps you have
an alternative suggestion?

Cheers,

Josef
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re[2]: Data.List.join

Bulat Ziganshin-2
Hello Josef,

Saturday, October 21, 2006, 5:43:24 PM, you wrote:

> It's just that I happen to like 'join' very much. But perhaps you have
> an alternative suggestion?

this pair is named split/join in other languages too

and quickcheck properties should be stolen from FPS, i think :)

prop_joinsplit c xs = join ([c]) (split c xs) == id xs



--
Best regards,
 Bulat                            mailto:[hidden email]

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Tomasz Zielonka
In reply to this post by Josef Svenningsson
On Sat, Oct 21, 2006 at 03:43:24PM +0200, Josef Svenningsson wrote:
> >But wait! There is also a join in Control.Monad!
> >
> Good point. But I don't really see that as a problem. Don't you think
> the two 'join's can co-exist?

Data.List and Control.Monad have no conflicting names at the moment.

On the other hand, you have a problem only when you use the conflicting
name in your code. Perhaps it wouldn't be so bad, but I tend to
use (concat . intersperse sep) a lot, and if I used join instead of that,
I would have to hide "join" from all my Control.Monad imports.

How about:
    separateWith
    sepBy (like in Parsec)
    joinWith
or in the spirit of concatMap:
    concatIntersperse
but that's a bit long.

Best regards
Tomasz
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Jeremy Shaw
At Sat, 21 Oct 2006 18:18:41 +0200,
Tomasz Zielonka wrote:

> or in the spirit of concatMap:
>     concatIntersperse

At Linspire, we have been calling this function 'consperse'.

j.
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Neil Mitchell
> At Linspire, we have been calling this function 'consperse'.

I've been calling this 'intercat' for some time now.

Thanks

Neil
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Clifford Beshers


Neil Mitchell wrote:
>> At Linspire, we have been calling this function 'consperse'.
>
> I've been calling this 'intercat' for some time now.

It would be nice if we could find a name that made it clear that:

    words = intercat " "

I don't like wordsBy, but maybe there is some other suffix that would do
the trick.
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re[2]: Data.List.join

Bulat Ziganshin-2
Hello Clifford,

Saturday, October 21, 2006, 11:16:02 PM, you wrote:
> It would be nice if we could find a name that made it clear that:

>     words = intercat " "

unwords? :)  i use joinWith in my program


--
Best regards,
 Bulat                            mailto:[hidden email]

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Donald Bruce Stewart
In reply to this post by Josef Svenningsson
Let's get join and split done!

I want to see this function done this time. So let's try hard not to
restart the big threads we've had on this topic in the last couple of
years. So I'll just point to the archives.
    http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/10136/focus=13631

Getting bogged down in fiddly details will just derail this effort. See
here. Perfectionists will not be tolerated! ;)
    http://haskell.org/haskellwiki/Protect_the_community

Now, in summary, Josef:
    * Send a patch to libraries@, for a minimal implementation of the join function
    * And a patch for QuickCheck properites, to live under testsuite/tests/*.
        - e.g. for split . join == id
                   words        == join " "
   
Now, the name, join conflicts, so:
    * consperse
    * connect
    * intercat
    * the problem with joinWith (or whatever) is that traditionally it would be joinBy

So, I propose we start with just, say, 'connect', with some QC
properties, and get that into base, before we get dragged out into a big
discussion about the entire api design.

-- Don
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

John Meacham
In reply to this post by Josef Svenningsson
On Sat, Oct 21, 2006 at 03:29:57PM +0200, Josef Svenningsson wrote:

> Hi,
>
> I'd like to propose to include the following function in Data.List:
> join :: [a] -> [[a]] -> [a]
> join x xs = concat (intersperse x xs)
>
> I find that every time I use intersperse I also concat the result. And
> it seems that I'm not alone:
> http://www.google.com/codesearch?q=file%3A%5C.hs+intersperse&btnG=Search+Code
> A clear majority of all the uses of intersperse also use concat on the
> result. I think it seems worthwhile to give a name to that idiom.
>
> The name 'join' was taken from Data.ByteString, where a similar function
> exists.
>
> All the best,
>

I have that same function in my standard toolbox, but call it

concatInter

a la concatMap.

though mconcatInter would probably be better, since then we can do it
for an arbitrary monoid.

        John

--
John Meacham - ⑆repetae.net⑆john⑈
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Jason Dagit-2
In reply to this post by Donald Bruce Stewart
On 10/21/06, Donald Bruce Stewart <[hidden email]> wrote:
> Let's get join and split done!
[snip]
> Now, the name, join conflicts, so:
>     * consperse
>     * connect
>     * intercat
>     * the problem with joinWith (or whatever) is that traditionally it would be joinBy

If we're going to have a split or splitBy then wouldn't the most
logical name be unsplit or unsplitBy?  I think consperse and intercat
are cute, but not that good because they don't really tell me what's
going on.  I think 'connect' is too vague and overloaded.  So yeah, my
vote is with unsplitBy.  On the other hand, whoever implments it
should get to choose the name and just be done with it :)

Anyway, just some fuel for the fire :)
Jason
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Udo Stenzel
In reply to this post by Donald Bruce Stewart
Donald Bruce Stewart wrote:
>     * the problem with joinWith (or whatever) is that traditionally it would be joinBy

You mean as in zipBy, exitBy, parZipBy, insertBy, unionBy, differenceBy,
fromListBy, showTreeBy, showListBy and applyBy?  I see, that's certainly
gonna be a problem.

I think, joinWith is actually a good choice.  The xxxBy functions take
ordering functions as argument, and that doesn't apply to joinWith.


Udo.
--
Si Hoc Legere Scis Nimium Eruditionis Habes.

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Jon Fairbairn
In reply to this post by Donald Bruce Stewart
On 2006-10-22 at 12:50+1000 [hidden email] (Donald Bruce Stewart)  wrote:
> Now, the name, join conflicts, so:
>     * consperse
>     * connect
>     * intercat
>     * the problem with joinWith (or whatever) is that traditionally it would be joinBy
>
> So, I propose we start with just, say, 'connect',

intercalate, surely?

OED says of intercalate:

   transf.  a. To insert or interpose something additional,
   extraneous, or out of the ordinary course, between the
   ordinary members of any series  [...]

Since there's already a word that means almost exactly what
we want, why not use it?

 Jón


--
Jón Fairbairn                              Jon.Fairbairn at cl.cam.ac.uk


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Henning Thielemann
In reply to this post by Josef Svenningsson

On Sat, 21 Oct 2006, Josef Svenningsson wrote:

> I'd like to propose to include the following function in Data.List:
> join :: [a] -> [[a]] -> [a]
> join x xs = concat (intersperse x xs)

analogously to
  concatMap = concat . map
we might prefer
  concatIntersperse = concat . intersperse
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Data.List.join

Josef Svenningsson
In reply to this post by Donald Bruce Stewart
On 10/22/06, Donald Bruce Stewart <[hidden email]> wrote:

> Let's get join and split done!
>
> I want to see this function done this time. So let's try hard not to
> restart the big threads we've had on this topic in the last couple of
> years. So I'll just point to the archives.
>     http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/10136/focus=13631
>
> Getting bogged down in fiddly details will just derail this effort. See
> here. Perfectionists will not be tolerated! ;)
>     http://haskell.org/haskellwiki/Protect_the_community
>
Well spoken.

> Now, in summary, Josef:
>     * Send a patch to libraries@, for a minimal implementation of the join function
>     * And a patch for QuickCheck properites, to live under testsuite/tests/*.
>         - e.g. for split . join == id
>                    words        == join " "
>
Patches attached.

I've also included a couple of properties that don't hold but which
one might think hold. I'm not sure how useful it is to have that in
the testsuite but I wanted to document them somewhere anyway.

> Now, the name, join conflicts, so:
>     * consperse
>     * connect
>     * intercat
>     * the problem with joinWith (or whatever) is that traditionally it would be joinBy
>
> So, I propose we start with just, say, 'connect', with some QC
> properties, and get that into base, before we get dragged out into a big
> discussion about the entire api design.
>
I think Jón's suggestion 'intercalate' was pretty sweet. I've chosen
to use that name in my patch.

Josef

basepatch (48K) Download Attachment
testsuitepatch (10K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re[2]: Data.List.join

Bulat Ziganshin-2
In reply to this post by Jon Fairbairn
Hello Jon,

Sunday, October 22, 2006, 4:18:27 PM, you wrote:

> intercalate, surely?

> Since there's already a word that means almost exactly what
> we want, why not use it?

it's a rare word that is unknown for english-guests like me



--
Best regards,
 Bulat                            mailto:[hidden email]

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: Data.List.join

Jon Fairbairn
On 2006-10-22 at 18:11+0400 Bulat Ziganshin wrote:

> Hello Jon,
>
> Sunday, October 22, 2006, 4:18:27 PM, you wrote:
>
> > intercalate, surely?
>
> > Since there's already a word that means almost exactly what
> > we want, why not use it?
>
> it's a rare word that is unknown for english-guests like me

В противоположность "Monad" например?

(Apologies for what is probably appalling grammar!) More
seriously, the more I think about it, the more I wonder if
giving names to things that have such a short expression as
“((concat .) . intersperse)” might not be counterproductive.

Whatever we call it, even if it's a word in an English
dictionary, it's meaning in Haskell becomes an additional
learning burden on a programmer who whishes to understand
programmes that use it. “(concat.).intersperse” might cause
some head scratching at first, but everything involved is
something that the programmer will have to learn anyway, and
if its use is frequent, it will become idiomatic.

 Jón

--
Jón Fairbairn                              Jon.Fairbairn at cl.cam.ac.uk


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
12345