Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on So you want to write a type checker (2014). Parent comment
Just to expand on my previous example, I can simply modify how bindings are looked up and generalize the associated type when it is not unknown:
type(V,Env,T) :- ground(V), member(V:P,Env), generalize(P,T). generalize(P,T) :- nonvar(P), !, copy_term(P,T). generalize(T,T).
type((A,B),Env,TA * TB) :- type(A,Env,TA), type(B,Env,TB). type(A+B,Env,number) :- type(A,Env,number), type(B,Env,number). type(let(X == XE, E),Env,ET) :- type(XE,Env,XT), type(E,[X:XT|Env],ET).
let(identity == lambda(v,v), let(increment == lambda(x,x+1), let(compose == lambda(f,lambda(g,lambda(x,apply(f,apply(g,x))))), (apply(apply(compose,identity),identity), apply(apply(compose,increment),increment)))))
(_1775 -> _1775) * (number -> number)
There are no comments on this comment yet.
Just to expand on my previous example, I can simply modify how bindings are looked up and generalize the associated type when it is not unknown:
Let's add two rules for tuples and addition, and change the syntax of let for clarity: Then, typing this: ... gives: You could also make use of meta attributes, ie. data stored inside variables, to control what happens during unification.