Movatterモバイル変換
[0]ホーム
\begin{code}moduleGHC.Show(Show(..),ShowS,shows,showChar,showString,showMultiLineString,showParen,showList__,showSpace,showLitChar,showLitString,protectEsc,intToDigit,showSignedInt,appPrec,appPrec1,asciiTab,)whereimportGHC.BaseimportData.MaybeimportGHC.List((!!),foldr1,break)importGHC.Generics(Arity(..),Associativity(..),Fixity(..))
\end{code}%*********************************************************%* *\subsection{The @Show@ class}%* *%*********************************************************\begin{code}typeShowS=String->StringclassShowawhereshowsPrec::Int->a->ShowSshow::a->StringshowList::[a]->ShowSshowsPrec_xs=showx++sshowx=showsx""showListlss=showList__showslssshowList__::(a->ShowS)->[a]->ShowSshowList___[]s="[]"++sshowList__showx(x:xs)s='[':showxx(showlxs)whereshowl[]=']':sshowl(y:ys)=',':showxy(showlys)appPrec,appPrec1::IntappPrec=I#10#appPrec1=I#11#
\end{code}%*********************************************************%* *\subsection{Simple Instances}%* *%*********************************************************\begin{code}instanceShow()whereshowsPrec_()=showString"()"instanceShowa=>Show[a]whereshowsPrec_=showListinstanceShowBoolwhereshowsPrec_True=showString"True"showsPrec_False=showString"False"instanceShowOrderingwhereshowsPrec_LT=showString"LT"showsPrec_EQ=showString"EQ"showsPrec_GT=showString"GT"instanceShowCharwhereshowsPrec_'\''=showString"'\\''"showsPrec_c=showChar'\''.showLitCharc.showChar'\''showListcs=showChar'"'.showLitStringcs.showChar'"'instanceShowIntwhereshowsPrec=showSignedIntinstanceShowa=>Show(Maybea)whereshowsPrec_pNothings=showString"Nothing"sshowsPrecp(Justx)s=(showParen(p>appPrec)$showString"Just ".showsPrecappPrec1x)s
\end{code}%*********************************************************%* *\subsection{Show instances for the first few tuples%* *%*********************************************************\begin{code}instance(Showa,Showb)=>Show(a,b)whereshowsPrec_(a,b)s=show_tuple[showsa,showsb]sinstance(Showa,Showb,Showc)=>Show(a,b,c)whereshowsPrec_(a,b,c)s=show_tuple[showsa,showsb,showsc]sinstance(Showa,Showb,Showc,Showd)=>Show(a,b,c,d)whereshowsPrec_(a,b,c,d)s=show_tuple[showsa,showsb,showsc,showsd]sinstance(Showa,Showb,Showc,Showd,Showe)=>Show(a,b,c,d,e)whereshowsPrec_(a,b,c,d,e)s=show_tuple[showsa,showsb,showsc,showsd,showse]sinstance(Showa,Showb,Showc,Showd,Showe,Showf)=>Show(a,b,c,d,e,f)whereshowsPrec_(a,b,c,d,e,f)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg)=>Show(a,b,c,d,e,f,g)whereshowsPrec_(a,b,c,d,e,f,g)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh)=>Show(a,b,c,d,e,f,g,h)whereshowsPrec_(a,b,c,d,e,f,g,h)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh,Showi)=>Show(a,b,c,d,e,f,g,h,i)whereshowsPrec_(a,b,c,d,e,f,g,h,i)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh,showsi]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh,Showi,Showj)=>Show(a,b,c,d,e,f,g,h,i,j)whereshowsPrec_(a,b,c,d,e,f,g,h,i,j)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh,showsi,showsj]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh,Showi,Showj,Showk)=>Show(a,b,c,d,e,f,g,h,i,j,k)whereshowsPrec_(a,b,c,d,e,f,g,h,i,j,k)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh,showsi,showsj,showsk]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh,Showi,Showj,Showk,Showl)=>Show(a,b,c,d,e,f,g,h,i,j,k,l)whereshowsPrec_(a,b,c,d,e,f,g,h,i,j,k,l)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh,showsi,showsj,showsk,showsl]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh,Showi,Showj,Showk,Showl,Showm)=>Show(a,b,c,d,e,f,g,h,i,j,k,l,m)whereshowsPrec_(a,b,c,d,e,f,g,h,i,j,k,l,m)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh,showsi,showsj,showsk,showsl,showsm]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh,Showi,Showj,Showk,Showl,Showm,Shown)=>Show(a,b,c,d,e,f,g,h,i,j,k,l,m,n)whereshowsPrec_(a,b,c,d,e,f,g,h,i,j,k,l,m,n)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh,showsi,showsj,showsk,showsl,showsm,showsn]sinstance(Showa,Showb,Showc,Showd,Showe,Showf,Showg,Showh,Showi,Showj,Showk,Showl,Showm,Shown,Showo)=>Show(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)whereshowsPrec_(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)s=show_tuple[showsa,showsb,showsc,showsd,showse,showsf,showsg,showsh,showsi,showsj,showsk,showsl,showsm,showsn,showso]sshow_tuple::[ShowS]->ShowSshow_tupless=showChar'('.foldr1(\sr->s.showChar','.r)ss.showChar')'\end{code}%*********************************************************%* *\subsection{Support code for @Show@}%* *%*********************************************************\begin{code}shows::(Showa)=>a->ShowSshows=showsPreczeroIntshowChar::Char->ShowSshowChar=(:)showString::String->ShowSshowString=(++)showParen::Bool->ShowS->ShowSshowParenbp=ifbthenshowChar'('.p.showChar')'elsepshowSpace::ShowSshowSpace=\xs->' ':xs\end{code}Code specific for characters\begin{code}showLitChar::Char->ShowSshowLitCharcs|c>'\DEL'=showChar'\\'(protectEscisDec(shows(ordc))s)showLitChar'\DEL's=showString"\\DEL"sshowLitChar'\\'s=showString"\\\\"sshowLitCharcs|c>=' '=showCharcsshowLitChar'\a's=showString"\\a"sshowLitChar'\b's=showString"\\b"sshowLitChar'\f's=showString"\\f"sshowLitChar'\n's=showString"\\n"sshowLitChar'\r's=showString"\\r"sshowLitChar'\t's=showString"\\t"sshowLitChar'\v's=showString"\\v"sshowLitChar'\SO's=protectEsc(=='H')(showString"\\SO")sshowLitCharcs=showString('\\':asciiTab!!ordc)sshowLitString::String->ShowSshowLitString[]s=sshowLitString('"':cs)s=showString"\\\""(showLitStringcss)showLitString(c:cs)s=showLitCharc(showLitStringcss)showMultiLineString::String->[String]showMultiLineStringstr=go'\"'strwheregochs=casebreak(=='\n')sof(l,_:s'@(_:_))->(ch:showLitStringl"\\"):go'\\'s'(l,_)->[ch:showLitStringl"\""]isDec::Char->BoolisDecc=c>='0'&&c<='9'protectEsc::(Char->Bool)->ShowS->ShowSprotectEscpf=f.contwhereconts@(c:_)|pc="\\&"++sconts=sasciiTab::[String]asciiTab=["NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US","SP"]\end{code}Code specific for Ints.\begin{code}intToDigit::Int->CharintToDigit(I#i)|i>=#0#&&i<=#9#=unsafeChr(ord'0'`plusInt`I#i)|i>=#10#&&i<=#15#=unsafeChr(ord'a'`minusInt`ten`plusInt`I#i)|otherwise=error("Char.intToDigit: not a digit "++show(I#i))ten::Intten=I#10#showSignedInt::Int->Int->ShowSshowSignedInt(I#p)(I#n)r|n<#0#&&p>#6#='(':itosn(')':r)|otherwise=itosnritos::Int#->String->Stringitosn#cs|n#<#0#=let!(I#minInt#)=minIntinifn#==#minInt#then'-':itos'(negateInt#(n#`quotInt#`10#))(itos'(negateInt#(n#`remInt#`10#))cs)else'-':itos'(negateInt#n#)cs|otherwise=itos'n#cswhereitos'::Int#->String->Stringitos'x#cs'|x#<#10#=C#(chr#(ord#'0'#+#x#)):cs'|otherwise=casechr#(ord#'0'#+#(x#`remInt#`10#))of{c#->itos'(x#`quotInt#`10#)(C#c#:cs')}\end{code}Instances for types of the generic deriving mechanism.\begin{code}derivinginstanceShowArityderivinginstanceShowAssociativityderivinginstanceShowFixity
\end{code}
[8]ページ先頭