Emojicode Documentation 0.8
Guides Language Reference Package Index

Types As Values

Emojicode allows you to pass types as value. You can then call type methods on these types or instantiate them.

The Type of a Type Value

Naturally, if you treat a type as value, this value must have a type as well. This type has the same name as the type the value represents but prefixed with the emoji, with which the type was defined. Let’s take a look at these examples:

πŸ–πŸ†• the_integer_type πŸ•ŠπŸ”’
πŸ–πŸ†• a_class_type πŸ‡πŸ”‘

In the example above two variables were declared. the_integer_type which can hold the type πŸ”’ and a_class_type which can hold the type πŸ”‘.

Note that you cannot use any built-in type like βšͺ️ or πŸ”΅ or optionals or errors as value. Furthermore, the type must always be prefixed with the appropriate emoji. A value type, for example, must be prefixed with πŸ•Š or the compiler will raise an error.

type-value ⟢ type-value-type-emoji type
type-value-type-emoji ⟢ πŸ‡ | πŸ•Š | πŸ¦ƒ | 🐊

Creating Type Values

Now let us create a type value. Type values are created exactly the same way their types are declared. So in order to populate our variables we can write this:

πŸ•ŠπŸ”’ ➑️ πŸ–the_integer_type
πŸ‡πŸ”‘ ➑️ πŸ–a_class_type

Voila!

Compatibility of Type Values

With the exception of classes, the type of two type values are only compatible if they are identical. The type of class type value, however, is compatible to another, if the former inherits from the latter.

The following is correct therefore:

πŸ‡ 🌷 πŸ‡πŸ‰

πŸ‡ 🌺 🌷 πŸ‡πŸ‰

🏁 πŸ‡
  πŸ–πŸ†• a_flower_type πŸ‡πŸŒ·
  πŸ‡πŸŒΊ ➑️ πŸ–a_flower_type
πŸ‰

Using Type Values

You can use type values whenever a type expression is expected with ⬛️:

type-from-expr ⟢ ⬛️ expression

expresssion must naturally evaluate to a type value.

πŸ• is a shortcut for β¬›οΈπŸ• when a type expression is expected.

The following example stores three different type values in a list, instantiates them at run-time and calls a method on these instances:

πŸ‡ 🐟 πŸ‡
  πŸ”‘ πŸ†• πŸ‡πŸ‰

  ❗️ πŸ™‹ πŸ‡
    πŸ˜€ πŸ”€I’m a fish.πŸ”€β—οΈ
  πŸ‰
πŸ‰

πŸ‡ 🐑 🐟 πŸ‡
  πŸ”‘ πŸ†• πŸ‡ β€΄οΈπŸ†•β—οΈ πŸ‰

  βœ’οΈ ❗️ πŸ™‹ πŸ‡
    πŸ˜€ πŸ”€I’m a blowfish.πŸ”€β—οΈ
  πŸ‰
πŸ‰

πŸ‡ πŸ‹ 🐟 πŸ‡
  πŸ”‘ πŸ†• πŸ‡ β€΄οΈπŸ†•β—οΈ πŸ‰

  βœ’οΈ ❗️ πŸ™‹ πŸ‡
    πŸ˜€ πŸ”€I’m a wale.πŸ”€β—οΈ
  πŸ‰
πŸ‰

πŸ‡ 🐠 🐟 πŸ‡
  πŸ”‘ πŸ†• πŸ‡ β€΄οΈπŸ†•β—οΈ πŸ‰

  βœ’οΈ ❗️ πŸ™‹ πŸ‡
    πŸ˜€ πŸ”€I’m a tropical fish.πŸ”€β—οΈ
  πŸ‰
πŸ‰

🏁 πŸ‡
  πŸ¨πŸ‡πŸŸ πŸ‡πŸ‘ πŸ‡πŸ‹ πŸ‡πŸ  πŸ† ➑️ classes
  πŸ”‚ class classes πŸ‡
    πŸ†•β¬›οΈ class πŸ†•β—οΈ ➑️ fish
    πŸ™‹ fish❗️
  πŸ‰
πŸ‰
← Previous Next Up: β€œDocumentation” β†’
Something not quite right? Improve this page