[Haskell-beginners] fold over elem?

Daniel Fischer daniel.is.fischer at web.de
Fri Sep 19 14:04:03 EDT 2008


Am Freitag, 19. September 2008 19:32 schrieb Logesh Pillay:
> I want to check if all the numbers in a list A are elements of a bigger
> unordered list B.
>
> Is there some way to fold  /A into elem /B?
>

I suppose what you want is an efficient way to check if all elements of A also 
belong to B?
I think if the type of elements belongs to Ord, your best bet, if B is large 
but not huge, is to sort B or build a Set from it and exploit the faster 
membership tests. If B is huge (or even infinite), that could require too 
much memory.

Cheers,
Daniel




More information about the Beginners mailing list