sylvan at student.chalmers.se
Tue Jun 13 19:34:43 EDT 2006
On 6/14/06, Jenny678 <mestor1 at gmx.de> wrote:
> I search a code for
> I have a code
> elements_in_List :: Eq a => [a] -> [a] -> Bool
> elements_in_List  _ = True
> elements_in_List _  = False
> elements_in_List (x:xs) (y:ys)
> | x == y = elements_in_List xs ys
> | True = elements_in_List (x:xs) ys
> but it failed at
> I hope somebody can help me
> Please don't use built-in-Functions.
> Thanks for Help
This sounds like homework so I'll just give some hints.
I think you would benefit from splitting this problem up a bit into a
couple of functions. There are many ways to solve it but think about
what kind of functions would help you solve this problem.
What if you had these two functions
isInList :: Eq a => a -> [a] -> Bool
removeFromList :: Eq a => a -> [a] -> [a]
Which would test for membership and remove a single element from a
list respectively. Would that help you?
Could you write these two functions yourself?
You could combine them of course:
findAndRemove :: Eq a => a -> [a] -> (Bool,[a])
or maybe even
findAndRemove :: Eq a => a -> [a] -> Maybe [a]
In the second case Nothing would represent that the element wasn't
found. This way would be better from an efficiency standpoint, but it
might be easier to define the two functions mentioned above (isInList
Try to figure out how to use these functions to achieve what you want,
then write them (and test independently!).
More information about the Haskell-Cafe