Name for split

Bart Massey bart at
Fri Jul 18 05:14:21 EDT 2008

Bart Massey <bart <at>> writes:
> I'd suggest that a reasonable definition of striate might be
>   striate :: (Eq a) => [a] -> [a] -> [[a]]
>   striate _ [] = [[]]
>   striate sep l | isPrefixOf sep l = [] : striate sep (drop (length sep) l)
>   striate sep (e  : es) = (e : l') : ls' where
>       (l' : ls') = striate sep es
> which seems to me pretty natural except for that odd definition on the empty
> list, but I think that's arguably a feature.  (Probably there's some clever
> fold or something I'm missing here.  Oh well.)

I know no one's listening, but I thought I'd correct myself on a couple of minor
points, for the record.

[BTW, the above paragraph was originally placed above the quoted text.  As a
result, gmane decided I was "top posting", and wouldn't let me continue.  That's
really obnoxious; I won't be posting here again until that bug is fixed.]

First of all, the correct geologic antonym for intercalate is stratify, not
striate.  Second of all, my definition fails badly with the empty separator.  We
can argue about whether it should do anything in this case, but it should at
least throw an error instead of generating an infinite list of nils.

My next shot at this:

    stratify :: (Eq a) => [a] -> [a] -> [[a]]
    stratify [] l = map (:[]) l
    stratify _ [] = [[]]
    stratify sep l | isPrefixOf sep l = [] : stratify sep (drop (length sep) l)
    striate sep (e  : es) = (e : l') : ls' where
        (l' : ls') = stratify sep es

The case of stratify [] [] is ugly now, though.  I dunno.

    Bart Massey
    bart at

More information about the Libraries mailing list