Reputation: 1137
Again the n00b here: trying Warp and WAI with the following code as in the documentation.
{-# LANGUAGE OverloadedStrings, DeriveGeneric #-}
import Network.Wai
import Network.HTTP.Types
import Network.Wai.Handler.Warp (run)
app3 :: Application
app3 request respond = respond $ case rawPathInfo request of
"/" -> index
"/raw/" -> plainIndex
_ -> notFound
plainIndex :: Response
plainIndex = responseFile
status200
[("Content-Type", "text/plain")]
"index.html"
Nothing
notFound :: Response
notFound = responseLBS
status404
[("Content-Type", "text/plain")]
"404 - Not Found"
Running plainIndex in GHCi returns:
<interactive>:12:1: error:
• No instance for (Show Response) arising from a use of ‘print’
• In a stmt of an interactive GHCi command: print it
*Main> :r
[1 of 1] Compiling Main ( WAI.hs, interpreted )
Two questions in one: can you help me out fixing this, and in exension to that: I am the only one frequently encountering issues like this when following documentation examples?
Upvotes: 0
Views: 271
Reputation: 3071
Running plainIndex
in GHCi, GHCi tries to compute the Response
and then print it in the terminal. A Show
instance defines how a given type should be represented as a String
. The library authors have chosen not to provide a Show
instance for Response
, probably to separate its representation from its interface.
Various parts of a response have Show
instances, so you can use accessors provided by Wai:
> responseStatus plainIndex
> responseHeaders plainIndex
More documentation for Response.
Upvotes: 1