【问题标题】:Yesod Not in scope: type constructor or class Form errorYesod 不在范围内:类型构造函数或类表单错误
【发布时间】:2021-03-31 03:55:30
【问题描述】:

我只是按照文档 blog example advanced 中的 Yesod 示例进行操作,但在执行 stack runghc main.hs 时出现此错误:

main.hs:186:14: error:
    Not in scope: type constructor or class ‘Form’
    Perhaps you meant one of these:
      ‘AForm’ (imported from Yesod), ‘MForm’ (imported from Yesod),
      ‘WForm’ (imported from Yesod)
    |
186 | entryForm :: Form Entry
    |              ^^^^

main.hs:237:27: error:
    Not in scope: type constructor or class ‘Form’
    Perhaps you meant one of these:
      ‘AForm’ (imported from Yesod), ‘MForm’ (imported from Yesod),
      ‘WForm’ (imported from Yesod)
    |
237 | commentForm :: EntryId -> Form Comment
    |

不确定它的真正含义。是因为使用的 Yesod 版本有些不同吗?我正在使用 Yesod 1.6.0.6。

完整代码是here

【问题讨论】:

  • 你链接的完整代码给了我404页。
  • 谢谢@Sibi,我的帐户刚刚被标记,不知道为什么,所以不允许粘贴这么长的文本。不是已经更新了。

标签: haskell yesod


【解决方案1】:

与博客中的内容相比,我看到您对Form 类型别名声明进行了评论并稍作修改。您需要在代码中的某处使用此行来定义 Form 是什么:

type Form x = Html -> MForm Handler (FormResult x, Widget)

那么,你将面临以下类型错误:

  • postBlogR的定义中,在entryId <- runDB $ insert entryForm的行中。问题是insert 需要输入Entry,而您提供entryForm :: Form Entry。我猜你是想通过entry 那里?
  • 与以前类似,但在 postEntryR 中:我想你想用 runDB $ insert comment 代替 runDB $ insert commentForm
  • commentForm:鉴于您没有在任何地方使用 entryId 参数并且它是范围内唯一似乎与类型匹配的东西,我推断您想用 entryId 替换 EntryId

在这些修复之后,代码在我这边用 yesod 1.6 编译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 2018-12-14
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    相关资源
    最近更新 更多