{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-}moduleData.Set.List(SetList(..))whereimportData.MonoidimportqualifiedData.ListasListimportPreludehiding(sum,concat,lookup,map,filter,foldr,foldr1,foldl,null,reverse,(++),minimum,maximum,all,elem,concatMap)importData.CollectionsimportData.Collections.BaseInstances()importData.Typeable-- | View a list of as a 'Set' collection.---- This allows to feed sequences into algorithms that require a Set without building a full-fledged Set.-- Most of the time this will be used only when the parameter list is known to be very small, such that-- conversion to a Set would be to costly.--FIXME: Generalize to sequences.newtypeSetLists=SetList{fromSetList::s}instance(Eqs,Eqa,Foldablesa)=>Eq(SetLists)where(SetListl1)==(SetListl2)=l1==l2||(sizel1==sizel2&&all(`elem`l1)l2)#include "Typeable.h"INSTANCE_TYPEABLE1(SetList,theTc,"Data.Set.List.SetList")instanceShowl=>Show(SetListl)whereshow(SetListl)="SetList "><showlinstanceFoldable(SetList[a])awherefoldrfz(SetListl)=foldrfzlnull(SetListl)=nulllinstanceEqa=>Set(SetList[a])awherehaddock_candy=haddock_candyinstanceEqa=>Monoid(SetList[a])wheremempty=emptymappend=unioninstanceEqa=>Unfoldable(SetList[a])awhereempty=SetListemptyinsertx(SetListl)=SetList$ifx`elem`lthenlelseinsertxlinstanceEqa=>Collection(SetList[a])awherefilterf(SetListl)=SetList$filterflinstanceEqa=>Map(SetList[a])a()whereisSubmapByfxy=isSubsetxy&&(f()()||null(intersectionxy))insertWith_fk()=insertkunionWith_f=unionintersectionWith_f=intersectionmapWithKey_f=iddifferenceWithfs1s2=iff()()==Nothingthendifferences1s2elses1lookupkl=ifmemberklthenreturn()elsefail"element not found"(SetListl1)`isSubset`(SetListl2)=all(`elem`l2)l1difference(SetListl1)(SetListl2)=SetList$(List.\\)l1l2deletek(SetListl)=SetList$filter(not.(k==))lmemberk(SetListl)=List.elemklunion(SetListl1)(SetListl2)=SetList$List.unionl1l2intersection(SetListl1)(SetListl2)=SetList$List.intersectl1l2alterfkl=letlk=lookupklincaselkofNothing->caseflkofNothing->lJust_->insertklJust_->caseflkofNothing->deleteklJust_->l