Emojicode Documentation 0.9
Guides Language Reference Package Index

Types and Namespaces


Emojicode uses namespaces to avoid problems with equally named types. If you, for instance, defined a type called 🌽 and you needed to import another package, which exports a type named 🌽 too, there would be a problem. To prevent this, you can import the package into another namespace.

In Emojicode types are not members of namespaces, but are available through namespaces. This also implies that a type may be reachable through several namespaces. The name of a namespace is always an emoji.

By default, that is when you specify no namespace, you access types through the namespace 🏠. You do this all the time, for instance when declaring a variable of string type:

πŸ–πŸ†• text πŸ”‘

When writing only πŸ”‘ the compiler assumes that the type is in the default namespace 🏠.

You can, of course, explicitly refer to a type in a namespace using the namespace accessor πŸ”Ά:

πŸ–πŸ†• text πŸ”ΆπŸ πŸ”‘

This denotes that we want the type πŸ”‘ reachable in the namespace 🏠.

This syntax can be used everywhere a type is expected. For example, to instantiate the type πŸ’‰ in the namespace πŸ₯, we would use:


Namespacing When Declaring a Type

By default, when you declare a type it will be available through the default namespace 🏠. It is possible to specify another namespace with the namespace accessor though:

πŸ‡ πŸ”ΆπŸ¨πŸ‘©β€πŸ’Ό πŸ‡


This declares a class πŸ‘©β€πŸ’Ό that will be reachable through the namespace 🏨.

Type Expectations

Emojicode uses a concept we call type expectations. Whenever an expression whose result must be compatible to a specific type is evaluated, this type becomes a type expectation.

When you call a method, for instance, the types of the parameters become type expectations. That is, if you defined a method that takes one argument of type πŸ”‘ and you call that method, the first argument will be expected to be a string. Another example would be a variable assignment. If you have declared a variable of a certain type, the compiler will expect this type when assigning to the variable.

Type Expectations are used in several cases (apart from ensuring that a value is of compatible type):

⚫️ The Expected Type

⚫️ (β€œthe expected type”) is an emoji that can be used instead of a type name.

The compiler will try to deduce the substituted type from the type expectation. Thus, ⚫️ will normally refer to the expected type.

⚫️ can be used in cases where writing out a type name in full is inconvenient, for example:

πŸ’­ πŸ€ is a type that requires a generic argument
πŸ–πŸ†• list πŸ¨πŸšπŸ€πŸšπŸ”‘πŸ†πŸ†

πŸ’­ ⚫️ stands for πŸ€πŸšπŸ”‘πŸ† here
πŸ”·βš«οΈπŸΈ ➑️ πŸ–list

Built-In Types

There are two special built-in types βšͺ and πŸ”΅.

βšͺ Something

βšͺ (something) is special as all types are compatible to it. This means that you can, for instance, store a value of any type into a variable of type βšͺ:

πŸ–πŸ†• surprise βšͺ
πŸ”€Anything, anything, anythingπŸ”€ ➑️ πŸ–surprise
1004 ➑️ πŸ–surprise

You cannot call any methods on βšͺ and you cast to βšͺ at run-time.

πŸ”΅ Someobject

All instances of classes are compatible to πŸ”΅ (someobject), but value type instances are not.

πŸ”² Type Casting

Type casting is a way to determine whether a value is of a given type at run-time and to treat the value as an instance of this type.

Type casting is implemented with the πŸ”² statement:

cast ⟢ πŸ”² expression type-expr

value is the value to be casted to type. If value can be casted to type value is returned as type. If value can’t be casted to type no value is returned. πŸ”² therefore returns an optional.

Don’t confuse type casting with type conversion. You can’t cast πŸ”’ to πŸ’―. In such a case you would have to use a suitable conversion method.


Type Casting may work incorrectly with generics in Emojicode 0.7.

βš–οΈ Size Of Type Instance

The βš–οΈ expression allows you to determine the number of bytes an instance of a provided type will take up at runtime:

size-of ⟢ βš–οΈ type

The following, for example, prints the size of an integer.

πŸ˜€ πŸ”‘ βš–οΈπŸ”’ 10❗️❗️


type-expr ⟢ ⚫️ | type-from-expr | type | this
type ⟢ [🍬] [✴️] type-main | 🚨 type type | βšͺ
type-main ⟢ variable | callable-type | type-identifier generic-arguments
type-main ⟢ 🍱 types 🍱 | πŸ”΅ | type-value
type-identifier ⟢ πŸ”Ά type-emoji type-emoji | type-emoji
types ⟢ type types | type
type-emoji ⟢ οΏ’βšͺ οΏ’πŸ”΅ ᅭ🍬 ᅭ🍱 οΏ’πŸ”Ά emoji-id
← Previous Next Up: β€œTypes As Values” β†’
Something not quite right? Improve this page