【发布时间】:2018-07-22 18:34:40
【问题描述】:
由于我无法通过记录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 记录的长度,也需要更新,所以我想知道是否有一种巧妙的方法来概括这个想法。
【问题讨论】: