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

Type inference fails with overload and record extension #66

Open
johnjcamilleri opened this issue Jul 1, 2020 · 1 comment
Open

Type inference fails with overload and record extension #66

johnjcamilleri opened this issue Jul 1, 2020 · 1 comment

Comments

@johnjcamilleri
Copy link
Member

Originally reported by Roman Suzi in gf-dev.

When trying to extend a record produced by an overloaded oper, type inference fails:

resource TestRes = {
  oper
    Rec: Type = {
      a, b: Str ;
    } ;

    mkRec1: Str -> Rec = \a -> { a = a; b = a } ;
    mkRec2: Str -> Str -> Rec = \a,b -> { a = a; b = b } ;
    
    mkRec = overload {
      mkRec: Str -> Rec = mkRec1 ;
      mkRec: Str -> Str -> Rec = mkRec2 ;
    } ;
    
    r1: Rec = mkRec1 "A" ** {a = "X"} ; -- ok
    r2: Rec = mkRec2 "A" "B" ** {a = "X"} ; -- ok

    r3: Rec = mkRec "A" "B" ; -- ok
    r4: Rec = mkRec "A" "B" ** {a = "X"} ; -- fails
    r5: Rec =
      let r: Rec = mkRec "A" "B"
      in  r ** {a = "X"} ; -- ok
    r6: Rec = <mkRec "A" "B": Rec> ** {a = "X"} ; -- fails
}

Error for r4:

 TestRes.gf:19:
   Happened in operation r4
    no overload instance of TestRes.mkRec
    with value type {b : Str}
    for argument list
      Str Str
    among alternatives
      Str
      Str Str

Error for r6:

 TestRes.gf:23:
   Happened in operation r6
    no overload instance of TestRes.mkRec
    with value type {a : Str; b : Str}
    for argument list
      Str Str
    among alternatives
      Str
      Str Str
@johnjcamilleri
Copy link
Member Author

Another thing that works:

  oper
    wrap: Rec -> Rec = \r -> r ;
    r7: Rec = wrap (mkRec "A" "B") ** {a = "X"} ; -- ok

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

No branches or pull requests

1 participant