Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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/...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: