我正在努力使用 HXT 库中的箭头根据列表(下面带有 mapM 的行)在树中生成元素。
mkqelem (mkQName vns "depositInstruction" pacNS) []
[selem "key"
[selem "accountId" [txt $ pacuAccountId pacUpdate],
selem "instructionId" [txt $ pacuInstructionId pacUpdate]
],
selem "totalAmount" [txt $ pacuTotalAmount pacUpdate],
mapM mkInvestment [(120, 10.0)]
]
mkInvestment :: ArrowXml a => (Fund, Amount) -> a n XmlTree
mkInvestment x = selem "investments" [selem "investmentId" [txt $ show $ fst x],selem "amount" [txt $ show $ snd x]]
该程序不会编译,我得到以下信息:
• Couldn't match type ‘[]’ with ‘XN.NTree’
Expected type: a n XmlTree
Actual type: a n [XmlTree]
• In the expression: mapM mkInvestment [(120, 10.0)]
In the third argument of ‘mkqelem’, namely
‘[mkelem
"key" [] [selem "accountId" [...], selem "instructionId" [...]],
selem "totalAmount" [txt $ pacuTotalAmount pacUpdate],
mapM mkInvestment [(120, 10.0)]]’
In the expression:
mkqelem
(mkQName vns "depositInstruction" pacNS)
[]
[mkelem
"key" [] [selem "accountId" [...], selem "instructionId" [...]],
selem "totalAmount" [txt $ pacuTotalAmount pacUpdate],
mapM mkInvestment [(120, 10.0)]]
我尝试用 += 的变体替换 mapM,但我对 Arrows 中的映射没有很好的直觉。任何指针?