Ask HN: Transpiling a dynamically typed language to a statically typed language
Hi, I have been pondering what I want to do for my master
thesis (2+ years away) and I have an idea. I am writing to ask if
the question has a known answer or is even theoretically possible
to conduct.
My idea is to write a source-to-source compiler from a Lisp_2 to Rust, but I do not know if it is possible to transpile from a dynamic language to a statically typed language. Is it?
9 comments
[ 2.0 ms ] story [ 45.0 ms ] threadfor libraries you can get the types from the library headers, "func a(foo int)" you know that x is int if they write "a(x)"
for new code just check the values assigned to variables (through all time); 1-10 as int, 1.xx-10.xx as float, etc. then use some switching to fill in the rest. but it never catches all the edge cases so you maybe you can use a foo<type> custom-syntax...
i did something similar for coffeescript to golang and i could get about 99% but i know it would break under real world conditions, ended with a custom syntax foo#type or foo<type>, and then they can use int8 and int16 and double and what not.
[1] http://dropbox.nakkaya.com/builds/ferret-manual.html [2] http://nakkaya.com/2011/06/29/ferret-an-experimental-clojure... (Old version for more documentation on the idea.) [3] https://en.wikipedia.org/wiki/Literate_programming
GC lang to non-GC lang is a more interesting challenge. If anyone has transpiled a gc lang to C++ I'd love to know how they did it.