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?
Running
plainIndexin GHCi, GHCi tries to compute theResponseand then print it in the terminal. AShowinstance defines how a given type should be represented as aString. The library authors have chosen not to provide aShowinstance forResponse, probably to separate its representation from its interface.Various parts of a response have
Showinstances, so you can use accessors provided by Wai:More documentation for Response.