
On 18/07/2012, at 12:37 PM, Brandon Allbery wrote:
On Tue, Jul 17, 2012 at 8:33 PM, Alvaro Gutierrez
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.