From be4e489380a71db40b3a1687ce0e0405eac468af Mon Sep 17 00:00:00 2001 From: Micah Kendall Date: Sun, 27 Nov 2022 00:30:25 +1100 Subject: [PATCH] Type-aliases explanation --- book/src/language-tour/type-aliases.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/book/src/language-tour/type-aliases.md b/book/src/language-tour/type-aliases.md index 8abbb316..9592adc9 100644 --- a/book/src/language-tour/type-aliases.md +++ b/book/src/language-tour/type-aliases.md @@ -1 +1,24 @@ # Type aliases + +A type alias lets you create a name which is identical to another type, without any additional information. +We like type names (including type alias names) to be PascalCase. + +```gleam +type MyNumber = Integer +``` + +I imagine them like variables for types. You could use this to simplify your type signatures for tuples. + +```gleam +type Person = (String, Integer) + +fn createPerson(name: String, age: Integer) -> Person { + (name, age) +} +``` + +If you want the type-alias to be accessible as a module, you should pub it. + +``` +pub type MyVector3 = (Integer, Integer, Integer) +``` \ No newline at end of file