I am working on the base of a language model, and am wondering how to represent the base type, which is a type Type
. I have heard of an "infinite chain of types", but (a) I can't seem to find it on the internet while searching anymore, and (b) I am not sure if that's what I need or what it really means in practice.
Basically, I have a system in the language like this:
type User
type String
type X
...
Internally these get compiled to something like this:
[
{
type: 'Type',
name: 'User'
},
{
type: 'Type',
name: 'String'
},
...
]
But actually, the type: 'Type'
gets further compiled not pointing to the string 'Type'
, but to the actual Type
object:
[
{
type: theTypeObject,
name: 'User'
},
{
type: theTypeObject,
name: 'String'
},
...
]
So then the problem is, I need to now define or specify the "type type" itself:
type Type
which I try represent in a similar way, so now we have:
[
{
type: 'Type',
name: 'Type'
},
...
]
which is:
let theTypeObject = { name: 'Type' }
typeTypeObject.type = theTypeObject
Is that correct? What is this really saying? It is a circular structure, does this even make sense conceptually?
What would be better to do in this situation? Or is this perfectly acceptable? Basically I would like to understand how to explain what this circular structure even means, because it just makes me confused.
The type "Type" is typed "Type". It is an element of itself...
That doesn't seem logically possible. So what should I do?
Type : Type
, as long as you are aware of the fact that it might allow you to write down a non-terminating program (which you can anyhow in a Turing-complete programming langauge). The more pressing issue is: are you implementing your language in Javascript or some such? Why? $\endgroup$Type
using the rules of the language itself? If a language is typed, and all objects must belong to at least one type, and types are also defined as objects, I understand that you need at least one built-in type in the machine model of the language itself. If all user-defined objects belong to a default typeTyped
, it makes no sense (practically, and not theoretically spoken) that such default type must be user-defined as well. $\endgroup$