假设我们有这样的数据类型:
data NodeProperties =
NodeProperties
{
p1 :: PropertyInfo Bool,
p2 :: PropertyInfo [String],
p3 :: PropertyInfo [String],
p4 :: PropertyInfo Bool,
p5 :: PropertyInfo [String]
}
deriving (Show, Data, Typeable)
我们有一个具有这种子句的修改函数:
| p1Prefix /= Nothing =
let
value = readBoolean p1Prefix
newProperties =
properties
{
p1 = (p1 properties){value = Just value}
}
in
modifyPropertiesNode pragmas newProperties
| p2Prefix /= Nothing =
let
value = readStringList p2Prefix
newProperties =
properties
{
p2 = (p2 properties){value = Just value}
}
in
modifyPropertiesNode pragmas newProperties
在我看来,最好将上面的代码推广到类似下面的代码。
| p1Prefix /= Nothing =
updateProperty p1 readBoolean p1Prefix pragmas
| p2Prefix /= Nothing =
updateProperty p2 readStringList p2Prefix pragmas
为了做这样的事情,我需要在记录赋值的左侧使用变量,似乎Haskell不喜欢这个想法。有没有替代方法来实现这一目标?