[英]Haskell Yesod and writeFile
I am trying to learn Yesod and trying to implement a simple REST app where everytime a I get a GET request I write something to a file.我正在尝试学习 Yesod 并尝试实现一个简单的 REST 应用程序,每次我收到GET请求时,我都会向文件中写入一些内容。 Right now I have the following handler function:现在我有以下处理程序函数:
getTestR =
do
return $ writeFile "test.txt" "Just something"
return $ object ["result" .= "Ok"]
What I was expecting is that the file test.txt
would be created and I would obtain a JSON with {result=Ok}
.我期待的是文件test.txt
将被创建,我将获得一个带有{result=Ok}
的 JSON。 However, I am obtaining the JSON, but the file is not being created.但是,我正在获取 JSON,但没有创建文件。
I guess the writeFile
is not being evaluated because of the lazy evaluation, but I have no idea how to overcome this problem.我猜想writeFile
由于懒惰评估而没有被评估,但我不知道如何克服这个问题。 Thanks in advance.提前致谢。
just use liftIO
:只需使用liftIO
:
getTestR =
do
liftIO $ writeFile "test.txt" "Just something"
return $ object ["result" .= "Ok"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.