【问题标题】:Error when using "#Bool" in the route在路由中使用“#Bool”时出错
【发布时间】:2016-03-12 17:11:03
【问题描述】:

我是yesod的初学者。 我正在尝试在 yesod 的路由文件中添加一个“/designmulti/key/#Int/name/#String/finished/#Bool PutDesignMultiR PUT”,但出现错误:

Foundation.hs:46:1:
      No instance for (PathPiece Bool)
      arising from a use of `toPathPiece'
    Possible fix: add an instance declaration for (PathPiece Bool)

是不是说yesod只支持Int和String,不支持Bool? 如何解决? 任何提示将不胜感激! 谢谢。

【问题讨论】:

  • 您需要添加 instance PathPiece Bool where ... ,它必须描述您希望从 uri 路径中解析布尔值的方式。
  • @pxqr 谢谢。我应该在哪里添加?在 Foundation.hs 中?
  • 我想是的。 Yesod 书有this chapter 在 yesod 中解释路由。
  • @pxqr 好的。非常感谢。
  • @SamvelTruzyan 既然你回答了这个问题,也许你应该发表你的评论作为答案?

标签: haskell yesod


【解决方案1】:

Yesod 使用对应类型的 PathPieces 实例解析 url 路径参数。为了解析 Bool 参数,您需要添加 instance PathPiece Bool,它应该描述您希望从一段 uri 路径解析 bool 的方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多