Reputation: 291
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?
Upvotes: 2
Views: 1925
Reputation: 27003
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
Upvotes: 7
Reputation: 7402
Are you using hugs
or ghc
? At the bottom of the wai webpage is the item titled `Doing without overloaded strings' that seems to address your problem. Try:
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as LB8
notFound = Response
{ status = Status404
, responseHeaders = [("Content-Type", B8.pack "text/plain")]
, responseBody = Right $ fromLBS $ LB8.pack "404 - Not Found"
}
Upvotes: 0