Primitive Types
Morph provides four fundamental primitive types.
Type Overview
| Type | Description | Example |
|---|---|---|
int | Integer numbers | 42, -7, 0 |
float | Floating-point numbers | 3.14, -0.5, 1.0 |
string | Text strings | "hello", "Morph" |
bool | Boolean values | true, false |
Integer (int)
Whole numbers without a decimal point:
age is 25 as int;
count is 0; // inferred as int
negative is -100;
Float (float)
Numbers with a decimal point:
pi is 3.14159 as float;
ratio is 0.5; // inferred as float
temperature is -40.0;
String (string)
Text enclosed in double quotes:
name is "Alice" as string;
greeting is "Hello, Morph!";
empty is "";
String concatenation uses +:
full is "Hello, " + name + "!";
Print(full); // Hello, Alice!
Boolean (bool)
The values true and false:
active is true as bool;
visible is false;
if (active) {
Print("Active!");
}
Default Type Inference
When no as annotation is provided, the compiler infers the type:
| Value | Inferred Type |
|---|---|
42 | int |
3.14 | float |
"text" | string |
true / false | bool |
Next Steps
- Type Annotation — Explicitly specifying types with
as - Dynamic — Untyped / late-bound variables