Re: [Haskell-cafe] stripSuffix

2012-07-18 Thread Evan Laforge
 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.

I also have 'rdrop' and 'rdropWhile' and 'rstrip' in my stdlib, and
use them regularly, if not frequently, along with List.isSuffixOf.

Yes, they're inefficient for long lists and hang on infinite ones, but
there are still lots of short lists out there.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] stripSuffix

2012-07-17 Thread Alvaro Gutierrez
Hi all --

Pardon me if this has been answered before: how come there's a
stripPrefix in Data.List, but no matching stripSuffix?

Thanks!
 Alvaro

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] stripSuffix

2012-07-17 Thread Brandon Allbery
On Tue, Jul 17, 2012 at 8:33 PM, Alvaro Gutierrez radi...@google.comwrote:

 Pardon me if this has been answered before: how come there's a
 stripPrefix in Data.List, but no matching stripSuffix?


Probably because prefixes are easier to do, given the nature of singly
linked lists.

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] stripSuffix

2012-07-17 Thread Richard O'Keefe

On 18/07/2012, at 12:37 PM, Brandon Allbery wrote:

 On Tue, Jul 17, 2012 at 8:33 PM, Alvaro Gutierrez radi...@google.com wrote:
 Pardon me if this has been answered before: how come there's a
 stripPrefix in Data.List, but no matching stripSuffix?
 
 Probably because prefixes are easier to do, given the nature of singly linked 
 lists. 

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.

It's so easy to write

stripSuffix sfx lst =
  case stripPrefix (reverse sfx) (reverse lst) of
Nothing - Nothing
Just ys - Just (reverse ys)

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.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] stripSuffix

2012-07-17 Thread Alvaro Gutierrez
On Tue, Jul 17, 2012 at 11:34 PM, Richard O'Keefe o...@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.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe