// `type` gives an existing type a new name; `alias` gives a function one.
import std.io.println;
import std.text.number;
type Celsius = int;
type Grid = vector vector int;
def add(left: int, right: int): int { return left + right; }
alias plus = add;
def main(): int {
let freezing: Celsius = 0;
let boiling: Celsius = 100;
println(int_to_text(plus(freezing, boiling)));
let row: vector int = [1, 2, 3];
let grid: Grid = [row];
println(int_to_text(grid[0][2]));
return 0;
}// `نوع` يعطي نوعا موجودا اسما جديدا، و`مرادف` يعطي دالة اسما جديدا.
استورد std.io.println;
استورد std.text.number;
نوع درجة_مئوية = عدد;
نوع شبكة = متجه متجه عدد;
عرف اجمع_عددين(اليسار: عدد, اليمين: عدد): عدد { أرجع اليسار + اليمين; }
مرادف زائد = اجمع_عددين;
عرف الرئيسية(): عدد {
دع التجمد: درجة_مئوية = 0;
دع الغليان: درجة_مئوية = 100;
اطبع_سطر(عدد_إلى_نص(زائد(التجمد, الغليان)));
دع الصف: متجه عدد = [1, 2, 3];
دع الشبكة: شبكة = [الصف];
اطبع_سطر(عدد_إلى_نص(الشبكة[0][2]));
أرجع 0;
}
Run it
With the interpreter, without compiling:
./build/sultanc run examples/en/data/type_aliases.snOr compile it to an executable:
./build/sultanc examples/en/data/type_aliases.sn -o build/example && ./build/example