微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

不在范围内的数据构造函数:无法识别的编译指示

如何解决不在范围内的数据构造函数:无法识别的编译指示

在完成网站第一个项目后,我想添加一些静态页面,我检查了以下 IHP - Recipes 静态页面。这就是我的处理方式:

web/Types.hs 中,我添加了以下内容

data StaticController      
  = WelcomeAction        
  | AboutAction          
  deriving (Eq,Show,Data)

Web/Static/About.hs

module Web.View.Static.About where
import Web.View.Prelude 

data About = About

instance View About where
   html About = [hsx| ~some html here~ |]

Web/Controller/Static.hs

module Web.Controller.Static where
import Web.Controller.Prelude
import Web.View.Static.Welcome
import Web.View.Static.About

instance Controller StaticController where
    action WelcomeAction = render WelcomeView
    action AboutAction   = render AboutView
                                       `

我得到的错误是:

Web/Controller/Static.hs:8:35
Data constructor not in scope: AboutView
|
|     action AboutAction   = render AboutView
|

build/Generated/Types.hs:3:1
Unrecognised pragma
|
| {-# GHC_OPTIONS -Wno-unused-imports,-Wno-dodgy-imports,-Wno-unused-matches #-}module    Generated.Types where
| ^^^

解决方法

您在名为 About 的数据类型中定义了视图。所以要渲染它,你应该调用 render About,而不是 render AboutView

我建议将 About 重命名为 AboutView,这更符合 IHP 约定:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。