moduleMath.Common.ListSetwhereimportData.List(group,sort)-- versions of Data.List functions which assume that the lists are ascending sets (no repeated elements)toListSetxs=maphead$group$sortxsisListSet(x1:x2:xs)=x1<x2&&isListSet(x2:xs)isListSet_=Trueunion(x:xs)(y:ys)=casecomparexyofLT->x:unionxs(y:ys)EQ->x:unionxsysGT->y:union(x:xs)ysunion[]ys=ysunionxs[]=xsintersect(x:xs)(y:ys)=casecomparexyofLT->intersectxs(y:ys)EQ->x:intersectxsysGT->intersect(x:xs)ysintersect__=[](x:xs)\\(y:ys)=casecomparexyofLT->x:(xs\\(y:ys))EQ->xs\\ysGT->(x:xs)\\ys[]\\_=[]xs\\[]=xssymDiff(x:xs)(y:ys)=casecomparexyofLT->x:symDiffxs(y:ys)EQ->symDiffxsysGT->y:symDiff(x:xs)yssymDiff[]ys=yssymDiffxs[]=xsdisjointxsys=null(intersectxsys)isSubset(x:xs)(y:ys)=casecomparexyofLT->FalseEQ->isSubsetxsysGT->isSubset(x:xs)ysisSubset[]_=TrueisSubset_[]=False-- Note that an ListSet.elem turned out to be slower than Data.List.elem-- (Perhaps because it's slower when x `notElem` xs)