我有一个类型
Handler [Maybe AvailableDay]
我想检查ghci中[Maybe AvailableDay]的内容.我怎么做?
我试着编译以下内容:
postRQuery :: Handler RepHtml
postRQuery = do
properties <- liftIO $ decodeFile "store" :: IO (Map String ())
defaultLayout [whamlet|Posted!|]
Run Code Online (Sandbox Code Playgroud)
但是我得到了以下编译器错误:
Couldn't match expected type `GGHandler
Bayith
Bayith
(Data.Enumerator.Iteratee
Data.ByteString.Internal.ByteString IO)
t0'
with actual type `IO (Map String ())'
In a stmt of a 'do' expression:
properties <- liftIO $ decodeFile "store" :: IO (Map String ())
Run Code Online (Sandbox Code Playgroud)
关于如何在Yesod处理程序中使用Data.Binary.decodeFile的任何想法?
网上有Haskell开发的首选linux发行版吗?特别是,我在本地进行了大量的Yesod开发,但是我的Web服务器运行的是RHEL(CentOS 5.8 i686),它并不是最无缝的体验.这不是一个与此相关的问题,但是,我想知道是否有一个分发(和/或托管服务提供商),它具有良好的Haskell支持,或者从您自己的经验中运作良好.
我对Haskell的IO有点新意,尽管我经常阅读它,但我的代码仍然无效.
我想要该应用程序做什么:
这是我到目前为止的代码.我可以确保函数"middle"在传递[String]时工作正常.
middle :: [a] -> a
middle xs = (drop ((l - 1) `div ` 2) xs) !! 0
where l = length xs
getSortedMiddleElement :: Int -> String
getSortedMiddleElement i = do
dat <- readFile $ "file" ++ (show i) ++ ".txt"
return $ middle $ sort $ lines dat
Run Code Online (Sandbox Code Playgroud)
我从"Int - > Content"函数(我使用Yesod)调用getSortedMiddleElement,其中数字通过URL传递,中间元素应该返回给用户.要从字符串中获取Content,它需要是"String",而不是"IO String"......如何轻松实现?
提前致谢!
我还有很多东西要学习Haskell,我在使用下面的代码时遇到了一些麻烦.我可以执行以下操作,但当然它会创建编译器警告,因为并非所有情况都显示在内case address s of,我想确保那些警告不存在:
postAddTenantR :: Handler Value
postAddTenantR = do
newTenantData <- parseJsonBody :: Handler (Result NewTenant)
case newTenantData of
Success s -> runDB $ do
newTenantGroup <- insert $ TenantGroup
_ <- insert $ Tenant (firstName s) (lastName s) (Just newTenantGroup)
case address s of
Just newAddress -> do
newProperty <- insert $ Property newAddress
insert $ Lease Nothing Nothing Nothing newProperty newTenantGroup
returnJson $ ProcessingResponse True Nothing
Error e -> returnJson $ ProcessingResponse False (Just …Run Code Online (Sandbox Code Playgroud) 我是Yesod的初学者,想要建立一个主要用静态文件构建的网站.
需要打开静态文件/,然后打开动态页面/foo.
所以我在static目录中准备了静态文件(例如,static/index.html,static/img/bar.gif,static/css/baz.css,...),并写成config/routes如下:
/ StaticR Static getStatic
/foo FooR GET POST
Run Code Online (Sandbox Code Playgroud)
Ghc声称
Exception when trying to run compile-time code:
Overlapping routes:
("StaticR","FooR")
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我想使用Yesod和Haskell来调用Pandoc,以将某种格式转换为其他格式。
pandocConverted :: String -> IO String
pandocConverted input = do
(Just hIn, Just hOut, _, _) <- createProcess (proc "pandoc" []) { std_in = CreatePipe, std_out = CreatePipe }
hPutStr hIn input
converted <- hGetContents hOut
return converted
Run Code Online (Sandbox Code Playgroud)
这很好。但是,如何翻译成其他格式?
例如,我怎么这样称呼pandoc?
pandoc -s README -o example4.tex
或这个?
pandoc -s -S -t docbook README -o example9.db
我试图了解Yesod的Hamlet中的变量插值,特别是实现if-then-else-like逻辑.假设我想根据整数的值添加CSS样式x.它x来自模板中的for循环,即我无法从Haskell代码访问它.
期望的结果:
<span class="even positive">2</span>
<span class="odd positive">13</span>
<span class="odd non-positive">-1</span>
<span class="even non-positive">0</span>
Run Code Online (Sandbox Code Playgroud)
尝试内联if:
<span class="#{if even x then "even" else "odd"} ...">#{x}</span>
Run Code Online (Sandbox Code Playgroud)
尝试使用$with:
$with cls <- (if even x then "even" else "odd")
<span class="#{cls}">#{x}</span>
Run Code Online (Sandbox Code Playgroud)
都不起作用; 两者都导致了
• Illegal variable name: ‘if’
When splicing a TH expression
Run Code Online (Sandbox Code Playgroud)
显然,Haskell语法的一部分未在#{...}解析器中实现.有干净的方法吗?我现在只能看到一条出路,它很丑陋地狱:
$if ((even x) && (x > 0))
<span class="even positive">#{x}</span>
$elseif (even x)
<span class="even non-positive">#{x}</span>
$elseif (x > 0) …Run Code Online (Sandbox Code Playgroud)