Yesod 不在范围内:类型构造函数或 class 表单错误

Yesod Not in scope: type constructor or class Form error

我只是按照文档 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

我看到您对 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 参数这一事实来看,它是范围内唯一似乎与类型匹配的东西,我推断您想要替换EntryIdentryId

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