我正在学习 Haskell,所以我决定编写一个 Web 应用程序。我确实选择了 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)]
| ^^^^^
我查看了一些示例项目(其中包括),但我不明白我做错了什么:(