Skip to content

Commit 7d390e8

Browse files
committed
Added type aliases and records
1 parent bc39951 commit 7d390e8

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

gleam/src/type_aliases.gleam

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub type Name = String
2+
pub type EmployeeId = Int
3+
4+
pub fn main() {
5+
let employee: Name = "John"
6+
let id: EmployeeId = 3243296
7+
8+
let string_type: String = "John"
9+
let int_type: Int = 3243296
10+
11+
echo string_type == employee
12+
echo int_type == id
13+
}

gleam/src/type_record.gleam

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub type Spaceship {
2+
Rocket(name: String, weight: Float, fuel_capacity: Float)
3+
Ufo(name: String, weight: Float, fuel_capacity: Float)
4+
Spaceshuttle(name: String, weight: Float, fuel_capacity: Float)
5+
}
6+
7+
pub fn main() {
8+
let rocket = Rocket(name: "Odyssey", weight: 234.53, fuel_capacity: 593.34)
9+
let ufo = Ufo(name: "Odyssey", weight: 123.6, fuel_capacity: 0.0)
10+
11+
let first_spaceshuttle =
12+
Spaceshuttle(name: "StarReacher 11", weight: 726.36, fuel_capacity: 1571.34)
13+
let second_spaceshuttle =
14+
Spaceshuttle(..first_spaceshuttle, name: "StarReacher 16")
15+
16+
echo rocket
17+
echo ufo
18+
echo first_spaceshuttle
19+
echo second_spaceshuttle
20+
}

gleam/test.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ gleam run -m triple_pipelines |
3737
gleam run -m triple |
3838
Compare-Object (Get-Content "$PSScriptRoot\..\test\triple_expected") |
3939
Assert-MatchTests &&
40+
gleam run -m type_aliases &&
4041
gleam run -m type_enum &&
42+
gleam run -m type_record &&
4143
gleam run -m unqualified_imports &&
4244
ForEach-Object 'foo';
4345

0 commit comments

Comments
 (0)