Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propapate type disambiguation to the record pattern #7582

Closed
vicuna opened this issue Jul 11, 2017 · 3 comments
Closed

propapate type disambiguation to the record pattern #7582

vicuna opened this issue Jul 11, 2017 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Jul 11, 2017

Original bug ID: 7582
Reporter: @ygrek
Assigned to: @gasche
Status: resolved (set by @gasche on 2017-07-11T21:13:47Z)
Resolution: duplicate
Priority: normal
Severity: feature
Version: 4.04.1
Category: language features
Duplicate of: #7389

Bug description

Given the following

module T = struct type t = { a : int; b : float } let create a b = { a; b } end;;

(1) Type of the returned value is propagated to the binding and compiler can resolve record fields just fine :

let unwrap () = let x = T.create 1 2. in (x.a,x.b);;

(2) But substituting with record pattern doesn't work :

let unwrap () = let {a;b} = T.create 1 2. in (a,b);;
Error: Unbound record field a

(3) Have to explicitly annotate record type :

let unwrap () = let {T.a;b} = T.create 1 2. in (a,b);;

Seems like a common pattern in code, would be nice to make (2) work?

Additional information

Same behaviour in 4.04.1 and 4.05.0+rc1

@vicuna
Copy link
Author

vicuna commented Jul 11, 2017

Comment author: @gasche

I asked the same question in #7389, but it turns out (see discussion there) that it is actually not easy to do this in a general and satisfying way.

@vicuna vicuna closed this as completed Jul 11, 2017
@vicuna
Copy link
Author

vicuna commented Jul 11, 2017

Comment author: @ygrek

Thanks, I looked for the duplicate but couldn't find it

@vicuna
Copy link
Author

vicuna commented Jul 11, 2017

Comment author: @gasche

Yeah, my title choice was pretty bad. No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants