Emojicode Documentation 1.0 beta 2

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


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 a class type value, however, is compatible with the type of the type value of its superclass.

The following is therefore correct:

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

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

🏁 πŸ‡
  πŸ–πŸ†• 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 whale.πŸ”€β—οΈ

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

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

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