definition:
|
ppDecl :: Options -> IDecl -> Doc
ppDecl opts (IInfixDecl inf prec qualId) =
let ppid = ppQualIdent opts 0 qualId
in ppInfix opts inf <+> ppPrecedence opts prec <+>
if isOperator (idName (qidIdent qualId)) then ppid else bquotes ppid
ppDecl opts (HidingDataDecl qualId mkind tvars)
| optWithHiding opts
= text "hiding data" <+> ppWithOptionalKind opts qualId mkind <+>
ppTypeVariables opts tvars
| otherwise = empty
ppDecl opts (IDataDecl qualId mkind tvars constrs pragmas) =
(if optWithInstance opts
then ppdata
else ppdata <$$>
ppDeriving (filter (isInstanceOf qualId) (optInstances opts)))
where
ppdatalhs = text "data" <+> ppWithOptionalKind opts qualId mkind <+>
ppTypeVariables opts tvars
ppdata = nest (optIndent opts)
(case constrs of
[] -> ppdatalhs
c:cs -> if optWithHiding opts -- show all details --> with line breaks
then ppdatalhs <$$> equals <+> ppConstructors opts constrs
else fillSep (ppdatalhs : (equals <+> ppConstructor opts c) :
map (bar <+>) (map (ppConstructor opts) cs))) <>
ppHiddenPragma opts pragmas
ppDeriving [] = empty
ppDeriving insts@(_:_) = hang 11 $
text " deriving" <+>
parensIf (length insts > 1)
((fillSep . punctuate (text ", ")) (map classOf insts))
where
classOf idecl = case idecl of
IInstanceDecl _ qid _ _ _ -> ppQualIdent opts 0 qid
_ -> empty -- should not occur
ppDecl opts (INewtypeDecl qualId mkind tvars newconstr pragmas) =
text "newtype" <+> ppWithOptionalKind opts qualId mkind <+>
ppTypeVariables opts tvars <+>
equals <+> ppNewConstructor opts newconstr <> ppHiddenPragma opts pragmas
ppDecl opts (ITypeDecl qualId mkind tvars texp) =
text "type" <+> ppWithOptionalKind opts qualId mkind <+>
ppTypeVariables opts tvars <+>
equals <+> ppType opts 0 texp
ppDecl opts (IFunctionDecl qualId prag ari qualTExp) =
nest (optIndent opts) $ fillSep
[ ppQualIdent opts 1 qualId
, ppMaybe (\x -> space <> ppMethodPragma opts x) prag
, if optWithArity opts then ppArity opts ari else empty
, doubleColon, ppQualType opts qualTExp ]
ppDecl opts (HidingClassDecl ctx qualId mkind ids fdeps)
| optWithHiding opts
= text "hiding class" <+> ppContext opts ctx <+>
ppWithOptionalKind opts qualId mkind <+>
hsep (map (ppTypeVariable opts) ids) <+> ppFunDeps opts fdeps
| otherwise = empty
ppDecl opts (IClassDecl ctx qualId mkind ids fdeps mDecls pragmas) =
text "class" <+> ppContext opts ctx <+>
ppWithOptionalKind opts qualId mkind <+>
hsep (map (ppTypeVariable opts) ids) <+> ppFunDeps opts fdeps <+>
ppMethodDecls opts mDecls <> ppHiddenPragma opts pragmas
ppDecl opts (IInstanceDecl ctx qualId itype mImpls mIdent)
| optWithInstance opts && (optWithImports opts || isNothing mIdent)
= text "instance" <+> ppContext opts ctx <+> ppQualIdent opts 0 qualId <+>
ppInstance opts itype <+>
ppImplementations opts mImpls <>
ppMaybe (\x -> space <> ppModulePragma opts x) mIdent
| otherwise = empty
|
iotype:
|
{(_,{IInfixDecl}) |-> _ || (_,{HidingDataDecl}) |-> _ || (_,{IDataDecl}) |-> _ || (_,{INewtypeDecl}) |-> _ || (_,{ITypeDecl}) |-> _ || (_,{IFunctionDecl}) |-> _ || (_,{HidingClassDecl}) |-> _ || (_,{IClassDecl}) |-> _ || (_,{IInstanceDecl}) |-> _}
|