我刚刚开始使用Spock,持久化和blaze-html开始Haskell web开发。forM_ block中的大火html类型错误
在我有的路线之一,我想加载我所选表中的每一行。我做这样的事情:
get ("/show/flight/" /> (var :: Var Integer)) $ \f -> requireUser $ \(_, l) -> do
fs
case fs of
[] -> blaze $ template False (showResultAlertBar False "Oops, something went wrong! Please try again.")
_ -> blaze $ template True (H.toHtml $ usersUsername l) loadFlightSeat
where
loadFlightSeat :: H.Html
loadFlightSeat =
forM_ fs $ \fs' -> do
sid
case sid of
Nothing -> H.div H.! A.class_ "alert alert-danger" $ "Oops, something went wrong! Please try again."
Just rid -> H.a H.! A.href (H.toValue $ "/flight/seat/" <> show c <> "/" <> show (fromIntegral $ (fromSqlKey . entityKey) sid)) H.! A.class_ "btn btn-theme" $ H.toHtml fs'
loadFlightInfos的类型是:
Integer -> SqlPersistM [Entity Flight]
和getSeatIdByFlight:
T.Text -> Integer -> SqlPersistM (Maybe (Entity Flight))
我从Spock的博客示例应用程序复制runSQL,它是这样的:
runSQL :: (HasSpock m, SpockConn m ~ SqlBackend) => SqlPersistT (NoLoggingT (ResourceT IO)) a -> m a
runSQL action = runQuery $ \conn -> runResourceT $ runNoLoggingT $ runSqlConn action conn
类型的错误我:
Couldn't match expected type ‘SqlBackend’
with actual type ‘SpockConn Text.Blaze.Internal.MarkupM’
In the expression: runSQL
In a stmt of a 'do' block:
sid
我还是不明白,这种类型的错误,因为我知道runSQL是从持续到斯波克的包装,如果我仅仅只是想输出HTML,为什么不能它通过类型检查?
如何解决此类型错误?
2015-08-14
SanShin