{-# LANGUAGE ExistentialQuantification, FlexibleInstances #-}{-# OPTIONS_HADDOCK not-home #-}moduleText.StringTemplate.Classes(SElem(..),StringTemplateShows(..),ToSElem(..),SMap,STShow(..),StFirst(..),Stringable(..),stShowsToSE)whereimportqualifiedData.MapasMimportData.ListimportData.MonoidimportqualifiedData.ByteString.Char8asBimportqualifiedData.ByteString.Lazy.Char8asLBimportqualifiedText.PrettyPrint.HughesPJasPPnewtypeStFirsta=StFirst{stGetFirst::Maybea}deriving(Eq,Ord,Read,Show)instanceMonoid(StFirsta)wheremempty=StFirstNothingr@(StFirst(Just_))`mappend`_=rStFirstNothing`mappend`r=rinstanceFunctorStFirstwherefmapfx=StFirst.fmapf.stGetFirst$xtypeSMapa=M.MapString(SElema)dataSElema=STRString|STSHSTShow|SM(SMapa)|LI[SElema]|SBLEa|SNull-- | The ToSElem class should be instantiated for all types that can be-- inserted as attributes into a StringTemplate.classToSElemawheretoSElem::Stringableb=>a->SElembtoSElemList::Stringableb=>[a]->SElembtoSElemList=LI.maptoSElem-- | The StringTemplateShows class should be instantiated for all types that are-- directly displayed in a StringTemplate, but take an optional format string. Each such type must have an appropriate ToSElem method defined as well.class(Showa)=>StringTemplateShowsawhere-- | Defaults to 'show'.stringTemplateShow::a->StringstringTemplateShow=show-- | Defaults to @ \ _ a -> stringTemplateShow a @stringTemplateFormattedShow::String->a->StringstringTemplateFormattedShow=flip$const.stringTemplateShow-- | This method should be used to create ToSElem instances for-- types defining a custom formatted show function.stShowsToSE::(StringTemplateShowsa,Stringableb)=>a->SElembstShowsToSE=STSH.STShowdataSTShow=foralla.(StringTemplateShowsa)=>STShowa-- | The Stringable class should be instantiated with care.-- Generally, the provided instances should be enough for anything.classMonoida=>StringableawherestFromString::String->astToString::a->String-- | Defaults to @ mconcatMap m k = foldr (mappend . k) mempty m @mconcatMap::[b]->(b->a)->amconcatMapmk=foldr(mappend.k)memptym-- | Defaults to @ (mconcat .) . intersperse @mintercalate::a->[a]->amintercalate=(mconcat.).intersperse-- | Defaults to @ mlabel x y = mconcat [x, stFromString "[", y, stFromString "]"] @mlabel::a->a->amlabelxy=mconcat[x,stFromString"[",y,stFromString"]"]instanceStringable[Char]wherestFromString=idstToString=idinstanceStringablePP.DocwherestFromString=PP.textstToString=PP.rendermconcatMapmk=PP.fcat.mapk$mmintercalate=(PP.fcat.).PP.punctuatemlabelxy=(xPP.$$PP.nest1y)instanceMonoidPP.Docwheremempty=PP.emptyx`mappend`y=xPP.<>yinstanceStringableB.ByteStringwherestFromString=B.packstToString=B.unpackinstanceStringableLB.ByteStringwherestFromString=LB.packstToString=LB.unpackinstanceStringable(EndoString)wherestFromString=Endo.(++)stToString=($[]).appEndo