Hacker News new | past | comments | ask | show | jobs | submit login

I designed and built a statically-typed F-Expr LISP for my thesis, using some partial AST evaluation to trace and ensure every value had at least an initial value, and from that, type inference.

So it looked like:

    (define fib
      (lambda (n)
        (let loop ((a 0) (b 1) (n n))
          (if (= n 0) a
          (loop b (+ a b) (- n 1)))))
Which would do nothing by itself, and be eliminated as dead code unless called.

If we called it with:

    (fib 10)
It would expand, after the macro stage, to:

    (define fib
      ((Type/Number lambda) ((Type/Number n))
        (let loop (((Type/Number a) 0) ((Type/Number b) 1) (n n))
          (if (= n 0) a
          (loop b (+ a b) (- n 1)))))
If a value couldn't be inferred after ensuring the validity of the AST, it was supposed to error out with some helpful messages, but tracing the entire AST forward and back repeatedly always managed to type every value that was at least initialised, and if not, eliminate it as dead code.

Tradeoffs:

Compiling can be very lengthy, and it would be theoretically possible to write a program that would take ridiculous times to compile.

Once compiled, we can ensure type safety, and in the underlying implementation, JIT everything for a decent amount of speed.

Edit: Forgot to add lambda return type. Then added it in the wrong place.




Do you happen to have a link to your thesis?


Unfortunately not.

I had to surrender publishing rights, and the university only publishes about 10 submissions a yeaar... So unlikely to appear anytime soon.


> I had to surrender publishing rights

Even as a pdf on your own webpage? What kind of university would do that? Even the most abusive CS publishers have a more relaxed policy…


Well, the nearest competitor requires full copyright transfer, so there's that.

And CS publishing usually happens only within STEM, not as a standalone, within this circle of Universities.

No, not in America. There is far less interest locally in CS, and so a sort of mild tyranny rules in academia.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: