Reputation: 1695
I'm learning Haskell so I decided to write a web app. I did choose PostgreSQL Simple to work with the database. I successfully connected to it and tried simple math operations but I'm having problems trying to map records to data. This code doesn't compile:
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)]
The error is:
‘fromRow’ is not a (visible) method of class ‘FromRow’
|
17 | fromRow = AnswersSet <$> field <*> field <*> field <*> field
| ^^^^^^^
And also:
‘toRow’ is not a (visible) method of class ‘ToRow’
|
20 | toRow r = [toField (sex r), toField (ageRange r), toField (country r), toField (commune r)]
| ^^^^^
I looked some sample projects (this among others) but I don't get what I'm doing wrong :(
Upvotes: 1
Views: 1002
Reputation: 4626
The module Database.PostgreSQL.Simple
only exports the type classes ToRow
and FromRow
, without any of their methods.
For those methods you need to import the modules Database.PostgreSQL.Simple.ToRow
and Database.PostgreSQL.Simple.FromRow
, as is done in the sample you linked to.
Upvotes: 7