gf-core
gf-core copied to clipboard
Type inference fails with overload and record extension
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
Another thing that works:
oper
wrap: Rec -> Rec = \r -> r ;
r7: Rec = wrap (mkRec "A" "B") ** {a = "X"} ; -- ok