r/ProgrammingLanguages • u/Tekmo • May 05 '26
A bidirectional typechecking puzzle
https://haskellforall.com/2026/05/a-bidirectional-typechecking-puzzle
36
Upvotes
r/ProgrammingLanguages • u/Tekmo • May 05 '26
5
u/LambdaFiend May 05 '26 edited May 05 '26
Hey, I've got a question! I've been implementing Local Contextual Type Inference, and your solution caught my attention.
From what I understood, you infer all elements and then check them with the computed most specific supertype. I came up with a similar idea, but gave up on it due to what seemed to me like a potentially serious backtracking problem.
Thus, now I'm left wondering: what do you think of that? Nested lists could prove to be hostile to the performance of the typechecking. It would be of great relief to have this cleared out, for it feels, indeed, quite limiting for a list's typability to depend on the inferrability of its head.
Cheers!
1
u/Forward_Paint_2045 May 05 '26
Interesting problem. Is the solution any different from how you would type check a conditional?
1
u/WalkerCodeRanger Azoth Language May 06 '26
One reason people don't do the least upper bound is that it is very easy for the inferred type to be too general. For example, Java had an issue where its equivalent of
let numbers = [ 1, 2, 1.1]would be inferred to be a list of object. If there is a supertype of all types in Grace (e.g.Any), be careful about when you infer the type list of any.