Proposal: Add isSubsequenceOf to Data.List

Joachim Breitner mail at joachim-breitner.de
Tue Oct 14 19:15:14 UTC 2014


Hi,


Am Montag, den 13.10.2014, 17:34 +0200 schrieb Niklas Hambüchen:
> `isSubsequenceOf` would go into the "Predicates" section
> (http://hackage.haskell.org/package/base-4.7.0.1/docs/Data-List.html#g:12)
> which already contains:
> 
> * isPrefixOf (dual of inits)
> * isSuffixOf (dual of tails)
> * isInfixOf
> 
> With this proposal, we would add
> 
> * isSubsequenceOf (dual of subsequences)

+1


> Suggested implementation:
> 
> -- | `isSubsequenceOf a b`: Checks if a is a subsequence of b.
> isSubsequenceOf :: (Eq a) => [a] -> [a] -> Bool
> isSubsequenceOf []    _                    = True
> isSubsequenceOf _     []                   = False
> isSubsequenceOf a@(x:a') (y:b) | x == y    = isSubsequenceOf a' b
>                                | otherwise = isSubsequenceOf a b

The docs should explain what a subsequence is (possibly by giving an
educating example, or referring to "subsequences").

Greetings,
Joachim

-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141014/db3c8615/attachment.sig>


More information about the Libraries mailing list