[Haskell-cafe] Re: Subsequence near solved hopefully

Sam Mason mason at f2s.com
Sun Oct 17 17:53:37 EDT 2004


Peter Simons wrote:
>This version should do it:
>
>isSubSeq :: (Eq a) => [a] -> [a] -> Bool
>isSubSeq   []     _    = True
>isSubSeq   _     []    = False
>isSubSeq (x:xs) (y:ys)
>  | x == y    = isSubSeq xs ys
                 ^^^^^^^^

I think you want to refer to List.isPrefixOf here - your version is a
sort of "ordered subset" test.  I.e. I get:

   "abc"  `isSubSeq`  ".a.b.c."   ===>   True

>  | otherwise = isSubSeq (x:xs) ys

My version would've been:

  isSubSeq x = any (isPrefixOf x) . tails

But Remi beat me to it (and for that I'll never forgive him! :-).

  Sam


More information about the Haskell-Cafe mailing list