[Haskell-cafe] Re: subsequence
Peter Stranney
peterstranney at yahoo.co.uk
Sun Oct 17 09:55:07 EDT 2004
>> I am stuck on an exercise in a haskell book (the craft of functional
>> programming) chapter 7 exercise 7.18 I have to write a function to
check
>> does one list occur as a subsequence of another, i am having real
>> difficulty trying to do this. I have a method which will tell me if
one
>> character occurs in the list but it won't work for a list of
>>characters.
>> the function should look like isSubsequence :: [chars] -> [chars] ->
>> boolean
>>
>Try writing a list or string equality function first? That may help.
Thanks for getting back to me, have written this so far
find :: [Char] -> Char -> Bool
find [] n = False
find (x:xs) n
| x == n = True
| otherwise = find xs x
this will work to find if one character appears in a list but i dont understand how to call this recursively to find if a list occurs within a list. I have tried writing another function to call this but it won't work. Does anyone have a solution?
thanks again
Peter Stranney
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20041017/fc0fa32f/attachment.htm
More information about the Haskell-Cafe
mailing list