{-# LANGUAGE TypeOperators #-}{-# LANGUAGE FlexibleInstances, FlexibleContexts #-}{-# LANGUAGE DefaultSignatures #-}moduleText.Show.PrettyVal(PrettyVal(prettyVal))whereimportData.RatioimportData.WordimportData.IntimportText.Show.ValueimportGHC.Generics-- | A class for types that may be reified into a value.-- Instances of this class may be derived automatically,-- for datatypes that support `Generics`.classPrettyValawhereprettyVal::a->ValuelistValue::[a]->ValuedefaultprettyVal::(GDump(Repa),Generica)=>a->ValueprettyVal=oneVal.gdump.fromdefaultlistValue::[a]->ValuelistValue=List.mapprettyValclassGDumpfwheregdump::fa->[(Name,Value)]instanceGDumpU1wheregdumpU1=[]instance(GDumpf,GDumpg)=>GDump(f:*:g)wheregdump(xs:*:ys)=gdumpxs++gdumpysinstance(GDumpf,GDumpg)=>GDump(f:+:g)wheregdump(L1x)=gdumpxgdump(R1x)=gdumpxinstancePrettyVala=>GDump(K1ta)wheregdump(K1x)=[("",prettyValx)]instance(GDumpf,Datatyped)=>GDump(M1Ddf)wheregdump(M1x)=gdumpxinstance(GDumpf,Constructorc)=>GDump(M1Ccf)wheregdumpc@(M1x)|conIsRecordc=[("",Recname(gdumpx))]|isTuplename=[("",Tuple(mapsnd(gdumpx)))]|otherwise=[("",Conname(mapsnd(gdumpx)))]wherename=conNamecisTuple('(':cs)=casespan(==',')csof(_,")")->True_->FalseisTuple_=Falseinstance(GDumpf,Selectors)=>GDump(M1Ssf)wheregdumpit@(M1x)=repeat(selNameit)`zip`mapsnd(gdumpx)oneVal::[(Name,Value)]->ValueoneValx=casexof[("",v)]->vfs|all(null.fst)fs->Con"?"(mapsndfs)|otherwise->Rec"?"fsmkNum::(Orda,Numa,Showa)=>(String->Value)->a->ValuemkNumcx|x>=0=c(showx)|otherwise=Neg(c(show(negatex)))instancePrettyValIntwhereprettyVal=mkNumIntegerinstancePrettyValIntegerwhereprettyVal=mkNumIntegerinstancePrettyValFloatwhereprettyValx=Float(showx)instancePrettyValDoublewhereprettyValx=Float(showx)instancePrettyValWord8whereprettyValx=Integer(showx)instancePrettyValWord16whereprettyValx=Integer(showx)instancePrettyValWord32whereprettyValx=Integer(showx)instancePrettyValWord64whereprettyValx=Integer(showx)instancePrettyValInt8whereprettyVal=mkNumIntegerinstancePrettyValInt16whereprettyVal=mkNumIntegerinstancePrettyValInt32whereprettyVal=mkNumIntegerinstancePrettyValInt64whereprettyVal=mkNumIntegerinstancePrettyValCharwhereprettyValx=Char(showx)listValuexs=StringxsinstancePrettyVala=>PrettyVal[a]whereprettyValxs=listValuexsinstance(PrettyVala,Integrala)=>PrettyVal(Ratioa)whereprettyValr=Ratio(prettyVal(numeratorr))(prettyVal(denominatorr))instance(PrettyVala1,PrettyVala2)=>PrettyVal(a1,a2)instance(PrettyVala1,PrettyVala2,PrettyVala3)=>PrettyVal(a1,a2,a3)instance(PrettyVala1,PrettyVala2,PrettyVala3,PrettyVala4)=>PrettyVal(a1,a2,a3,a4)instance(PrettyVala1,PrettyVala2,PrettyVala3,PrettyVala4,PrettyVala5)=>PrettyVal(a1,a2,a3,a4,a5)instance(PrettyVala1,PrettyVala2,PrettyVala3,PrettyVala4,PrettyVala5,PrettyVala6)=>PrettyVal(a1,a2,a3,a4,a5,a6)instance(PrettyVala1,PrettyVala2,PrettyVala3,PrettyVala4,PrettyVala5,PrettyVala6,PrettyVala7)=>PrettyVal(a1,a2,a3,a4,a5,a6,a7)