Rewriting algorithm w in Rust using indexes for type variables.
I had rewritten this in F# from ocaml and the usage of ref made it simple but this can't work in rust so I opted for using indexes.
Original implementation from this repo: https://github.com/tomprimozic/type-systems