问题描述
我是Haskell的新手,我试图让wai包工作(因为我对使用Haskell进行web应用感兴趣)。我试着从主页中的第一个最简单的例子开始:
[1] { - #LANGUAGE OverloadedStrings# - }
[2] import Network.Wai
[3] import Network.Wai .enumerator(fromLBS)
[4] import Network.Wai.Handler.SimpleServer(run)
[5]
[6] app :: Application
[7] app _ = return response
[8] {status = status200
[9],responseHeaders = [(Content-Type,text / plain)]
[10],responseBody = ResponseLBS 你好,网络!
[12]
[13] main :: IO()
[14] main = do
[15] putStrLn $http: // localhost:8080 /
[16]运行8080应用程序
上面的代码(与runhaskell),我得到以下错误:
wapp.hs:10:36:
没有实例为(Data.String.IsString
Data.ByteString.Lazy.Internal.ByteString)
在wapp.hs:10:36-48的字面值`'Hello,Web!''中产生
可能的修正:
为
(Data.String.IsString
Data.ByteString.Lazy.Internal.ByteString)添加一个实例声明
在 ResponseLBS'的第一个参数中,即
Hello,Web!'
记录的`responseBody'字段
在'return'的第一个参数中,即
`Response
{status = status200,
responseHeaders = [(Content-Type,text / plain)],
responseBody = ResponseLBS网页!} '
这个例子有什么问题(我不这么认为,因为它来自wai主页 - 它应该是正确的!),或者是我的Haskell系统出了什么问题?
为要用作重载字符串的类型导出 IsString
实例。看起来你并没有导入任何模块为懒惰的bytestrings导出 IsString
实例。尝试将此导入添加到您的代码中:
import Data.ByteString.Lazy.Char8
I'm a Haskell newbie, and I'm trying to get the wai package working (because I'm interested in using Haskell for web applications). I tried to start with the first, simplest example from the wai homepage:
[ 1] {-# LANGUAGE OverloadedStrings #-}
[ 2] import Network.Wai
[ 3] import Network.Wai.Enumerator (fromLBS)
[ 4] import Network.Wai.Handler.SimpleServer (run)
[ 5]
[ 6] app :: Application
[ 7] app _ = return Response
[ 8] { status = status200
[ 9] , responseHeaders = [("Content-Type", "text/plain")]
[10] , responseBody = ResponseLBS "Hello, Web!"
[11] }
[12]
[13] main :: IO ()
[14] main = do
[15] putStrLn $ "http://localhost:8080/"
[16] run 8080 app
When I run the code above (with runhaskell), I get the following error:
wapp.hs:10:36: No instance for (Data.String.IsString Data.ByteString.Lazy.Internal.ByteString) arising from the literal `"Hello, Web!"' at wapp.hs:10:36-48
Possible fix: add an instance declaration for (Data.String.IsString Data.ByteString.Lazy.Internal.ByteString)
In the first argument of ResponseLBS', namely
"Hello, Web!"'
In the `responseBody' field of a record
In the first argument of `return', namely
`Response
{status = status200,
responseHeaders = [("Content-Type", "text/plain")],
responseBody = ResponseLBS "Hello, Web!"}'
Is it something wrong with the example (I don't think so, because it's from the wai homepage - it should be correct!), or is it something wrong with my Haskell system?
You need to import modules that export IsString
instances for the types you want to use as overloaded strings. It looks like you're not importing any module that exports an IsString
instance for lazy bytestrings. Try adding this import to your code:
import Data.ByteString.Lazy.Char8
这篇关于Haskell:最简单的例子是一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!