“toRow”不是 class“ToRow”的(可见)方法

‘toRow’ is not a (visible) method of class ‘ToRow’

我正在学习 Haskell 所以我决定编写一个网络应用程序。我确实选择了 PostgreSQL Simple 来处理数据库。我成功连接到它并尝试了简单的数学运算,但我在尝试将记录映射到数据时遇到问题。此代码无法编译:

module Handlers.SurveyReplies where

import Database.PostgreSQL.Simple

data AnswersSet = AnswersSet {
  sex ∷ Integer,
  ageRange ∷ Integer,
  country ∷ Integer,
  commune ∷ Maybe Integer
} deriving (Show)

instance FromRow AnswersSet where
  fromRow = AnswersSet <$> field <*> field <*> field <*> field

instance ToRow AnswersSet where
toRow r = [toField (sex r), toField (ageRange r), toField (country r), toField (commune r)]

错误是:

    ‘fromRow’ is not a (visible) method of class ‘FromRow’
   |
17 |   fromRow = AnswersSet <$> field <*> field <*> field <*> field
   |   ^^^^^^^

还有:

    ‘toRow’ is not a (visible) method of class ‘ToRow’
   |
20 |         toRow r = [toField (sex r), toField (ageRange r), toField (country r), toField (commune r)]
   |         ^^^^^

我查看了一些示例项目 (this among others),但我不明白我做错了什么:(

模块 Database.PostgreSQL.Simple 仅导出类型 类 ToRowFromRow,没有它们的任何方法。

对于这些方法,您需要导入模块 Database.PostgreSQL.Simple.ToRowDatabase.PostgreSQL.Simple.FromRow,就像您链接到的示例中所做的那样。