Are you going to check all the lists one by one, or do you need to check all possible pairs?
I would check out a lot of very small lists against one.
I asked because one problem is converting too many small lists using fromList . Since one of the lists is fixed, you can avoid most of this cost by converting only a fixed list.
import qualified Data.Set as S import Data.Set (Set) -- There is probably a better name for this modified version. commonEle :: (Ord a) => Set a -> [a] -> Bool commonEle xs ys = any (`S.member` xs) ys
If you are writing a puzzle game, you can save this part of the puzzle state forever as Set , so you don’t need to recreate the set every time. (If you need to save additional information related to positions, there are also Map types from Data.Map / Data.Map.Strict / Data.HashMap ).
In any case, follow Karsten’s advice: "The best way to find out is to try it (measure)." Also, do not forget to check the promised performance characteristics for the functions that you plan to use in the documentation of the corresponding modules.
source share