鉴于this我用来学习Haskell的小项目,我想将我的请求处理程序代码生成移动到Hamlet模板,但我不确定如何传递问题。
当取消注释行时,我的当前代码会生成以下错误,这是第一个阻止程序:
Couldn't match expected type `String -> String' with actual type `String' In the return type of a call of `renderHtml' Probable cause: `renderHtml' is applied to too many arguments In the expression: renderHtml ($ (shamletFile "fileList.hamlet")) In an equation for `myTemplate': myTemplate = renderHtml ($ (shamletFile "fileList.hamlet"))
代码:
site :: Snap ()
site =
ifTop (writeBS "hello world") <|>
route [ ("foo", writeBS "ba"),
("view_root_json_files", listRootFilesHandler)
] <|>
dir "static" (serveDirectory ".")
--myTemplate :: String -> String
--myTemplate = renderHtml ( $(shamletFile "fileList.hamlet") )
toText :: [FilePath] -> Text
toText = foldMap (flip snoc '\n' . pack)
listRootFilesHandler :: Snap ()
listRootFilesHandler = do
filenames <- liftIO $ getDirectoryContents "data"
let filtered_filenames = filter (not . isPrefixOf ".") filenames
writeText $ toText filtered_filenames
答案 0 :(得分:2)
Ghc告诉你正确的类型签名。只需将String -> String
替换为String
。