Is not record field punning possible(try link)?
type count = {num: int}
let num = 4
let countexample = {{num}}
Is not record field punning possible(try link)?
type count = {num: int}
let num = 4
let countexample = {{num}}
Punning with one attribute has ambiguities with a new { }
scope.
you need to do {num: num}
for single attribute records.
In contrast, if you have more than one attribute, this works perfectly fine.
type count = {num: int, num2: int}
let num = 4
let num2 = 4
let countexample = {
{num, num2}
}
I’ve noticed that:
let countexample = {num, num2}
gets reformatted to:
let countexample = {num: num, num2: num2}
Is this deliberate? I like how field punning makes code concise.
Apparently, it was overlooked:
Seems to work with a trailing comma for single field records:
let countexample = {
{ num, }
}
And using parens also work but it is pretty much equivalent to the scope version, looks a bit better in a single line:
let countexample = ({ num, })
If you click “format” the punning gets replaced with { num: num }
It’s not a bug currently, but it is inconsistent. We’ll see what we can do.