我有一个迭代记录类型列表的函数:
let resAddr (ranges: IpRanges list) =
ranges
|> List.iter (fun e ->
{
let {ipStart=ipStart;ipEnd=ipEnd;subnet=subnet;gateway=gateway} = e
printfn "%O" ipStart
})
编译器抱怨错误
Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'
我做错了什么?
答案 0 :(得分:4)
不要将函数体放在括号中,F#不使用大括号,它使用空格。因此,请确保正确识别您的功能。
let resAddr (ranges: IpRanges list) =
ranges
|> List.iter (fun e ->
let { ipStart=ipStart; ipEnd=ipEnd; subnet=subnet; gateway=gateway } = e
printfn "%O" ipStart
)
另外,我发现当我的函数变成多行时,我通常更喜欢单独声明它们以帮助提高可读性
let resAddr (ranges: IpRanges list) =
let internalHandleRange range =
let { ipStart=ipStart; ipEnd=ipEnd; subnet=subnet; gateway=gateway } = range
printfn "%O" ipStart
ranges
|> List.iter internalHandleRange