[Haskell-cafe] Missing join and split

David Roundy droundy at darcs.net
Sat Dec 29 14:18:28 EST 2007

On Fri, Dec 28, 2007 at 04:24:38PM +0100, Benja Fallenstein wrote:
> On Dec 28, 2007 3:55 PM, David Roundy <daveroundy at gmail.com> wrote:
> > On Dec 28, 2007 9:51 AM, Benja Fallenstein <benja.fallenstein at gmail.com> wrote:
> > > If you use intercalate to join, I would presume that you would want to
> > > use an inverse of it to split. I'd write it like this:
> >
> > Of course, there is no inverse to intercalate
> Right; I misspoke. What I meant was that you would want a split such that
>     intercalate a (split a xs) = a
> for finite, total (a,xs) (and, since it's achievable, even for
> infinite xs). Of course, (split a xs = [xs]) satisfies that, but if we
> add the requirement that split is also supposed to do its job :-) then
> I think split is fully specified except for whether (split a [] = [])
> or (split a [] = [[]]). The latter seems better to me; e.g., it
> satisfies
>     split a (x ++ a ++ y) = split a x ++ split a y

Yes, the latter is what darcs' linesPS does.

> > so if you want to use a "logical" approach, perhaps you'd want to
> > define split first, and then define your join as the inverse of split.
> If your join comes out as being intercalate, I suppose it's six of
> one, half a dozen of the other :-)

Well, your intercalate "\n" is not the same as "unlines" and the inverse of
intercalate "\n" is not the same as lines, nor is its inverse (with " ")
the same as words.  It is true that intercalate " " is the same as unwords,
however.  So it does seem like the prelude doesn't really give us any hints
as to what would be a useful generic join/split pair.
David Roundy
Department of Physics
Oregon State University

More information about the Haskell-Cafe mailing list