[Haskell-cafe] Re: Subsequence near solved hopefully
Remi Turk
rturk at science.uva.nl
Sun Oct 17 18:04:33 EDT 2004
On Sun, Oct 17, 2004 at 10:53:37PM +0100, Sam Mason wrote:
> 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
as Ketil pointed out, this "subsequence" test may be exactly what
the OP meant.
> 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
But I only gave the point-free and the point-wise version: You
did the half-of-a-point version ;) (which I would actually have
used myself too) *ducks and runs*[1]
Groetjes,
Remi
[1] and falls asleep
--
Nobody can be exactly like me. Even I have trouble doing it.
More information about the Haskell-Cafe
mailing list