2014-08-31 2 views
1

Мой текущий код генерирует следующее сообщение об ошибке, когда линии являются раскомментирована, который является первым блокатор:Snap render list in 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 

ответ

2

GHC говорит вам правильную сигнатуру типа поставить там. Просто замените String -> String на String.