Addendum: Encoding tuples with numbers
I described how to encode tuples of natural numbers into natural numbers. Now, I wrote (hacked) a small piece in Haskell to try it in practice.
So here it is:
decode do most of the work. Note that this implementation includes also the number 0 (by accident, since computers usually index lists starting with 0). However, as mentioned in the original post, it’s not a very practicable solution, since we have to deal with quite large numbers and factorize them.
The program can probably be sped up by explicitly stating the types of the functions and compiling the program. I omitted them because my compiler always complained about incompatible types (
The program can be tested by simply calling
decode (encode [1,2,3,4,5]) or similar.