4 ms·
Considering the two existing ways to defines structs are type S = struct val X:int end type [<Struct>] R = val Y:int it's not new syntax as much as an ext
by cloudroutine 10y ago
Considering the two existing ways to defines structs are
type S = struct val X:int end
type [<Struct>] R = val Y:int
it's not new syntax as much as an extension of the contexts where the construct is applicable.
The examples in the blog post aren't in accordance with the RFC as far as type signatures are concerned [1] The tuple decomposition is mixed in with the type sig.
let getPointFromOffset (point: struct (x, y)) (offset: struct (dx, dy)) = ...
^ is totally wrong
let getPointFromOffset (struct(x, y) as point) (struct (dx, dy) as offset) = ...
or
let getPointFromOffset ((x, y): struct(int * int)) ((dx, dy): struct(int * int)) = ...
use the proper syntax, which is consistent with the rest of F#
[1] https://github.com/fsharp/FSharpLangDesign/blob/master/RFCs/FS-1006-struct-tuples.md#examples-and-error-messages https://github.com/fsharp/FSharpLangDesign/blob/master/RFCs/...