Module("collection/list/sort",[Imports([Import("collection/list/common")]),Rules([RDef("SortL",[DefaultVarDec("s")],Rule(NoAnnoList(ListTail([Var("x"),Var("y")],Var("l"))),NoAnnoList(ListTail([Var("y"),Var("x")],Var("l"))),BA(CallNoArgs(SVar("s")),NoAnnoList(Tuple([Var("x"),Var("y")]))))),RDef("LSort",[DefaultVarDec("s")],Rule(NoAnnoList(ListTail([Var("x")],Var("l"))),NoAnnoList(ListTail([Var("y"),Var("x")],Var("l'"))),AM(BA(Call(SVar("at-suffix"),[Scope(["ys"],Seq(Match(NoAnnoList(ListTail([Var("y")],Var("ys")))),Seq(Where(BA(CallNoArgs(SVar("s")),NoAnnoList(Tuple([Var("x"),Var("y")])))),Build(Var("ys")))))]),Var("l")),Var("l'")))),RDef("LMerge",[DefaultVarDec("s")],Rule(NoAnnoList(ListTail([Var("x")],Var("l"))),NoAnnoList(ListTail([Var("z")],Var("l'"))),AM(BA(Call(SVar("at-suffix"),[LRule(Rule(NoAnnoList(ListTail([Var("y")],Var("ys"))),Var("ys"),AM(BA(CallNoArgs(SVar("s")),NoAnnoList(Tuple([Var("x"),Var("y")]))),Var("z"))))]),Var("l")),Var("l'"))))]),Strategies([SDef("sort-list",[DefaultVarDec("s")],Call(SVar("try"),[Rec("x",Seq(LChoice(CallNoArgs(SVar("s")),ListCong([Id],CallNoArgs(SVar("x")))),Call(SVar("try"),[CallNoArgs(SVar("x"))])))])),SDef("isort-list",[DefaultVarDec("s")],Call(SVar("try"),[Rec("x",Seq(LChoice(ListCong([Id],CallNoArgs(SVar("x"))),CallNoArgs(SVar("s"))),Call(SVar("try"),[CallNoArgs(SVar("x"))])))])),SDef("jsort-list",[DefaultVarDec("s")],Call(SVar("try"),[Rec("x",LChoice(ListCong([Id],CallNoArgs(SVar("x"))),Seq(CallNoArgs(SVar("s")),Call(SVar("try"),[CallNoArgs(SVar("x"))]))))])),SDefNoArgs("uniq",Let([SDefNoArgs("Uniq",LRule(RuleNoCond(NoAnnoList(ListTail([Var("x")],Var("xs"))),NoAnnoList(ListTail([Var("x")],App(Call(SVar("filter"),[Not(Match(Var("x")))]),Var("xs")))))))],Call(SVar("listtd"),[Call(SVar("try"),[CallNoArgs(SVar("Uniq"))])])))]),Strategies([SDef("qsort",[DefaultVarDec("swap")],Let([SDefT("swapper",[],[DefaultVarDec("a2")],BA(CallNoArgs(SVar("swap")),NoAnnoList(Tuple([RootApp(Id),Var("a2")]))))],Call(SVar("quick-sort"),[CallNoArgs(SVar("swapper"))])))]),Strategies([SDef("quick-sort",[VarDec("swap",FunType([ConstType(SortVar("a")),ConstType(SortVar("a"))],ConstType(SortVar("b"))))],CallT(SVar("quick-sort"),[CallNoArgs(SVar("swap"))],[NoAnnoList(List([]))])),RDefT("quick-sort",[VarDec("swap",FunType([ConstType(SortVar("a")),ConstType(SortVar("a"))],ConstType(SortVar("b"))))],[DefaultVarDec("tail")],RuleNoCond(NoAnnoList(List([])),Var("tail"))),RDefT("quick-sort",[VarDec("swap",FunType([ConstType(SortVar("a")),ConstType(SortVar("a"))],ConstType(SortVar("b"))))],[DefaultVarDec("tail")],Rule(NoAnnoList(ListTail([Var("x")],Var("xs"))),App(CallT(SVar("quick-sort"),[CallNoArgs(SVar("swap"))],[NoAnnoList(ListTail([Var("x")],Var("tail'")))]),Var("smaller")),Seq(AM(Assign(Var("smaller"),App(Call(SVar("retain-all"),[Where(CallT(SVar("swap"),[],[Var("x")]))]),Var("xs"))),Var("a")),Seq(Assign(Var("bigger"),App(Call(SVar("remove-all"),[Where(CallT(SVar("swap"),[],[Var("x")]))]),Var("xs"))),Assign(Var("tail'"),App(CallT(SVar("quick-sort"),[CallNoArgs(SVar("swap"))],[Var("tail")]),Var("bigger")))))))])])
