[Haskell-cafe] elementsinlist

Bryan Burgers bryan.burgers at gmail.com
Tue Jun 13 19:34:33 EDT 2006


On 6/13/06, Jenny678 <mestor1 at gmx.de> wrote:
>
> Hallo
> I search a code for
>
> >elements_in_List([1,2],[1,2]).
> >True
> >elements_in_List([1,8],[1,2,3,4,8]).
> >True
> >elements_in_List([2,1],[1,2]).
> >True
> >elements_in_List([1,1],[1]).
> >False
>
> 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
> >elements_in_List([2,1],[1,2]).
> >True
>
> I hope somebody can help me
> Please don't use built-in-Functions.
>
> Thanks for Help

I haven't looked too far into this, but how about something like this:

elements_in_list a b = and $ map (\x -> element_in_list x b) a
   where element_in_list = ...

Maybe if you don't want to use built-in functions, define your own
'and' as well.

Bryan


More information about the Haskell-Cafe mailing list