softshipper
softshipper

Reputation: 34071

Invalid record, sequence or computation expression

I have a function that iterate over a list of a record type:

let resAddr (ranges: IpRanges list) =
    ranges
    |> List.iter (fun e ->
                 {
                    let {ipStart=ipStart;ipEnd=ipEnd;subnet=subnet;gateway=gateway} = e
                    printfn "%O" ipStart
                 })

The compiler complain with error

Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'

What am I doing wrong?

Upvotes: 0

Views: 896

Answers (1)

wasatz
wasatz

Reputation: 4278

Don't put the function body in braces, F# doesn't use braces for blocks, it uses whitespace. So just make sure to ident your function correctly.

let resAddr (ranges: IpRanges list) =
    ranges
    |> List.iter (fun e ->
                      let { ipStart=ipStart; ipEnd=ipEnd; subnet=subnet; gateway=gateway } = e
                      printfn "%O" ipStart
                 )

Also, I find that when my functions becomes more than one line I usually prefer to declare them separately like this to help readability

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

Upvotes: 4

Related Questions