首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WAI教程-无实例(显示响应)

WAI教程-无实例(显示响应)
EN

Stack Overflow用户
提问于 2018-12-04 11:50:07
回答 1查看 244关注 0票数 0

同样,这里的n00b :使用以下代码尝试Warp和WAI,如文档中所示。

代码语言:javascript
复制
{-# 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"

在plainIndex中运行GHCi返回:

代码语言:javascript
复制
<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 )

一个问题中有两个问题:你能帮我解决这个问题吗?我是唯一一个经常遇到这样的问题的人。

EN

回答 1

Stack Overflow用户

发布于 2018-12-04 16:59:57

plainIndex中运行GHCi,GHCi尝试计算Response,然后在终端中打印。Show实例定义了如何将给定类型表示为String。库作者选择不为Response提供Response实例,可能是为了将其表示与接口分离。

响应的各个部分都有Show实例,因此可以使用Wai提供的访问器

代码语言:javascript
复制
> responseStatus plainIndex
> responseHeaders plainIndex

更多的供答复的文件

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53612336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档