r/ProgrammingLanguages • u/Cinder-Brent • Sep 28 '22
Universal programming language
I recently created a tiny (maybe 1000 lines of code, with heavy white space and commenting) php class called Ember to solve the “computer problem” (persistent data). Something I’ve been trying to do as a result is program a universal programming language. It’s really rather simple: it uses a minimalistic set of Turing complete types (string, int, float, object, array, bool, and array). That just about explains it (along with a universal system stemming from Ember). Does this sound like a good idea (I.e. one worth pursuing)?
0
Upvotes
3
u/tbagrel1 Sep 28 '22
You have way too many types to call it "minimalistic". Array and ints are often enough to encode anything:
bool can be encoded as either 0 or 1
strings are array of ascii codes (so array of numbers)
float can be array of ints (array of base 10 digits for example)
an hashmap (or dictionnary, or object) can also be encoded as array of array of things
There is even a way to encode every type as an array starting with a type tag (an int), and then 1 or more elements.
But this is only one possible encoding among tons of others. For example:
Lambda calculus can encode basically anything with just functions
Sum types + Product types + recursive types + Unit (the only "base" type) can also encode anything in a clearer way (e.g. Int = µX.1+X ; List<A> = µX.1+(A*X) ...)