[Haskell-cafe] stripSuffix
Alvaro Gutierrez
radical at google.com
Wed Jul 18 06:10:56 CEST 2012
On Tue, Jul 17, 2012 at 11:34 PM, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
> Here are two other possible reasons.
>
> It's not just easier, stripPrefix pfx lst is *possible* as long
> as pfx is finite, even when lst is infinite. The same would not
> be true of a suffix stripper.
Isn't this the case with isSuffixOf, though? And yet it's there along
with isPrefixOf...
> It's so easy to write
>
> stripSuffix sfx lst =
> case stripPrefix (reverse sfx) (reverse lst) of
> Nothing -> Nothing
> Just ys -> Just (reverse ys)
Sure, it's not difficult to write such a function; the issue is the
asymmetry (and thus, broken user expectations) based on the rest of
the library.
> I can think of two cases where I'd want something like this.
> One is manipulating file extensions, where I'd want to use
> System.FilePath.splitExtension or something like that anyway.
> The other is suffix stripping for text processing, where I'd
> want to use a trie to match a whole lot of possible suffixes.
For what it's worth, there are a lot of other cases (outside of file
path handling) in which I've found it useful.
More information about the Haskell-Cafe
mailing list