False False Nothing Nothing Nothing
]
⧺
- if useGZip then
- [ ImportDecl (⊥) (ModuleName "Codec.Compression.GZip")
- False False Nothing Nothing Nothing
- ]
- else
- []
+ [ ImportDecl (⊥) (ModuleName "Codec.Compression.GZip")
+ False False Nothing Nothing Nothing
+ | useGZip
+ ]
resourceDecl ∷ Name → Bool → [Decl]
resourceDecl symName useGZip
resHead ∷ Exp
resHead
- = infixApp (var $ name "Just")
- (op $ name "$" )
- (doE [ foundEntityStmt
- , setContentTypeStmt
- ])
+ = function "Just" `app`
+ paren (doE [ foundEntityStmt
+ , setContentTypeStmt
+ ])
resGetGZipped ∷ Exp
resGetGZipped
- = infixApp (var $ name "Just")
- (op $ name "$" )
- (doE [ foundEntityStmt
- , setContentTypeStmt
- , bindGZipStmt
- , conditionalOutputStmt
- ])
+ = function "Just" `app`
+ paren (doE [ foundEntityStmt
+ , setContentTypeStmt
+ , bindGZipStmt
+ , conditionalOutputStmt
+ ])
where
condVarName ∷ Name
condVarName = name "gzipAllowed"
bindGZipStmt
= genStmt (⊥)
(pvar condVarName)
- (metaFunction "isEncodingAcceptable" [strE "gzip"])
+ (function "isEncodingAcceptable" `app` strE "gzip")
conditionalOutputStmt ∷ Stmt
conditionalOutputStmt
(doE [ setContentEncodingGZipStmt
, outputStmt (var dataVarName)
])
- (metaFunction "output"
- [paren (metaFunction "decompress" [var dataVarName])])
+ ( function "output"
+ `app`
+ paren (function "decompress" `app` var dataVarName)
+ )
resGetRaw ∷ Exp
resGetRaw
- = infixApp (var $ name "Just")
- (op $ name "$" )
- (doE [ foundEntityStmt
- , setContentTypeStmt
- , outputStmt (var $ name "rawData")
- ])
+ = function "Just" `app`
+ paren (doE [ foundEntityStmt
+ , setContentTypeStmt
+ , outputStmt (var $ name "rawData")
+ ])
setContentEncodingGZipStmt ∷ Stmt
setContentEncodingGZipStmt
- = qualStmt $
- metaFunction "setContentEncoding" $
- [ listE [ strE "gzip" ] ]
+ = qualStmt
+ ( function "setContentEncoding"
+ `app`
+ listE [ strE "gzip" ]
+ )
foundEntityStmt ∷ Stmt
foundEntityStmt
= qualStmt $
- metaFunction "foundEntity" $
- [ var $ name "entityTag"
- , var $ name "lastModified"
- ]
+ metaFunction "foundEntity"
+ [ var $ name "entityTag"
+ , var $ name "lastModified"
+ ]
setContentTypeStmt ∷ Stmt
setContentTypeStmt
- = qualStmt $
- metaFunction "setContentType" $
- [var $ name "contentType"]
+ = qualStmt
+ ( function "setContentType"
+ `app`
+ var (name "contentType")
+ )
outputStmt ∷ Exp → Stmt
outputStmt e
- = qualStmt $
- metaFunction "output" [e]
+ = qualStmt $ function "output" `app` e
entityTagDecl ∷ ETag → [Decl]
entityTagDecl eTag
varName = name "entityTag"
valExp ∷ Exp
- valExp = metaFunction "parseETag" [strE $ eTagToString eTag]
+ valExp = function "parseETag" `app` strE (eTagToString eTag)
lastModifiedDecl ∷ UTCTime → [Decl]
lastModifiedDecl lastMod
varName = name "lastModified"
valExp ∷ Exp
- valExp = metaFunction "read" [strE $ show lastMod]
+ valExp = function "read" `app` strE (show lastMod)
contentTypeDecl ∷ MIMEType → [Decl]
contentTypeDecl mime
varName = name "contentType"
valExp ∷ Exp
- valExp = metaFunction "parseMIMEType" [strE $ mimeToString mime]
+ valExp = function "parseMIMEType" `app` strE (mimeToString mime)
mimeToString ∷ MIMEType → String
mimeToString = A.toString ∘ A.fromAsciiBuilder ∘ printMIMEType
" Compression: gzip\n"
else
" Compression: disabled\n"
- , " MIME Type: ", show mimeType, "\n"
+ , " MIME Type: ", mimeTypeToString mimeType, "\n"
, " ETag: ", eTagToString eTag, "\n"
, " Last Modified: ", show localLastMod, "\n"
, " -}"
eTagToString ∷ ETag → String
eTagToString = A.toString ∘ A.fromAsciiBuilder ∘ printETag
+mimeTypeToString ∷ MIMEType → String
+mimeTypeToString = A.toString ∘ A.fromAsciiBuilder ∘ printMIMEType
+
getModuleName ∷ [CmdOpt] → IO ModuleName
getModuleName opts
= case modNameOpts of
- [] → fail "a module name must be given."
- (OptModName modName):[] → return $ ModuleName modName
- _ → fail "too many --module options."
+ [] → fail "a module name must be given."
+ OptModName modName:[] → return $ ModuleName modName
+ _ → fail "too many --module options."
where
modNameOpts ∷ [CmdOpt]
modNameOpts = filter (\ x → case x of
getSymbolName ∷ [CmdOpt] → ModuleName → IO Name
getSymbolName opts (ModuleName modName)
= case symNameOpts of
- [] → return defaultSymName
- (OptSymName symName):[] → return $ name symName
- _ → fail "too many --symbol options."
+ [] → return defaultSymName
+ OptSymName symName:[] → return $ name symName
+ _ → fail "too many --symbol options."
where
symNameOpts ∷ [CmdOpt]
symNameOpts = filter (\ x → case x of
getMIMEType opts srcFile
= case mimeTypeOpts of
[] → return defaultType
- (OptMIMEType ty):[]
+ OptMIMEType ty:[]
→ case A.fromChars ty of
Just a → return $ parseMIMEType a
Nothing → fail "MIME type must not contain any non-ASCII letters."
getETag ∷ [CmdOpt] → Lazy.ByteString → IO ETag
getETag opts input
= case eTagOpts of
- [] → return $ mkETagFromInput
- (OptETag str):[] → return $ strToETag str
- _ → fail "too many --etag options."
+ [] → return mkETagFromInput
+ OptETag str:[] → return $ strToETag str
+ _ → fail "too many --etag options."
where
eTagOpts ∷ [CmdOpt]
eTagOpts = filter (\ x → case x of
openOutput ∷ [CmdOpt] → IO Handle
openOutput opts
= case outputOpts of
- [] → return stdout
- (OptOutput fpath):[] → openFile fpath WriteMode
- _ → fail "two many --output options."
+ [] → return stdout
+ OptOutput fpath:[] → openFile fpath WriteMode
+ _ → fail "two many --output options."
where
outputOpts ∷ [CmdOpt]
outputOpts = filter (\ x → case x of