moduleHoogle.Score.Scoring(scoring)whereimportHoogle.Score.TypeimportData.ListimportControl.ArrowimportData.OrdimportData.MaybeimportControl.MonadimportSystem.Random-- | Given a set of scores, where the first is lower than the second, returns details for how to rank scores.-- This function is in the 'IO' monad since it may require randomness, and it may output status messages while solving,-- particularly if in Verbose mode.scoring::[(Score,Score)]->IOStringscoringxs=doletcostys=sum[max0$1+valsa-valsb|(a,b)<-xs,letvals=sum.map(fromRange.fromJust.fliplookupys).scoreCosts]config<-solveConfigcost[(x::TypeCost,toRange[1..10])|x<-[minBound..maxBound]]return$unlines["cost "++showa++" = "++show(fromRangeb)|(a,b)<-config]----------------------------------------------------------------------- SOLVERtypeCost=Int-- zipper on the valuedataRangea=Range[a]a[a]derivingShowtoRange(x:xs)=Range[]xxsfromRange(Range_x_)=xtypeConfig=[(TypeCost,RangeInt)]bestConfigf=snd.minimumBy(comparingfst).map(f&&&id)nextRange(Rangeabc)=[Rangeasa(b:c)|a:as<-[a]]++[Range(b:a)ccs|c:cs<-[c]]nextConfig=perturb$\(a,b)->map((,)a)$nextRangebrandomRange(Rangexyz)=doletxs=reversex++y:zi<-randomRIO(0,lengthxs-1)let(x2,y2:z2)=splitAtixsreturn$Range(reversex2)y2z2randomConfig=mapM$\(a,b)->fmap((,)a)$randomRangeb-- | Greedy hill climbing to improve a configimproveConfig::(Config->Cost)->Config->ConfigimproveConfigfnow|fnext<fnow=improveConfigfnext|otherwise=nowwherenext=bestConfigf$nextConfignow-- | Try and minimize the cost of the configsolveConfig::(Config->Cost)->Config->IOConfigsolveConfigfx=fmap(bestConfigf)$replicateM25$doputChar'.'y<-randomConfigxletz=improveConfigfyprint(fy,fz)returnz-- | Perturb one value in the listperturb::(a->[a])->[a]->[[a]]perturbf[]=[[]]perturbf(x:xs)=map(:xs)(fx)++map(x:)(perturbfxs)