由于我无法map
超过记录,因此我发现的最佳方法是使用蛮力:
data Item = Item {
vendor :: Int,
lotNumber :: Int,
description :: String,
reserve :: Maybe Double,
preSaleBids :: Maybe Double,
salePrice :: Maybe Double,
purchaser :: Maybe Int,
saleID :: Maybe Int
}
hsToDb :: Item -> [SqlValue]
hsToDb (Item a b c d e f g h) = [toSql a, toSql b, toSql c, toSql d, toSql e, toSql f, toSql g, toSql h]
dbToHs :: [SqlValue] -> Item
dbToHs [a,b,c,d,e,f,g,h] = Item (fromSql a) (fromSql b) (fromSql c) (fromSql d) (fromSql e) (fromSql f) (fromSql g) (fromSql h)
这段代码看起来很难看,如果我改变Item
记录的长度也需要更新,所以我想知道是否有一种聪明的方法来概括这个想法。