So a simple thing occured to me today. Rather than worry about the correct behavior for a join/split pair, we should just add unintercalate to the library. A bit verbose as a name, but at least there's no ambiguity.

--s

On Dec 29, 2007, at 2:18 PM, David Roundy wrote:

On Fri, Dec 28, 2007 at 04:24:38PM +0100, Benja Fallenstein wrote:
On Dec 28, 2007 3:55 PM, David Roundy <[EMAIL PROTECTED]> wrote:
On Dec 28, 2007 9:51 AM, Benja Fallenstein <[EMAIL PROTECTED]> 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
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to