Skip to content

Commit

Permalink
Document import type
Browse files Browse the repository at this point in the history
Closes #61
  • Loading branch information
lpil committed Mar 26, 2024
1 parent ed8c00f commit ccf75d2
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/content/chapter0_basics/lesson14_type_imports/code.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import gleam/bytes_builder
import gleam/string_builder.{type StringBuilder}

pub fn main() {
// Referring to a type in a qualified way
let _bytes: bytes_builder.BytesBuilder = bytes_builder.new()

// Refering to a type in an unqualified way
let _text: StringBuilder = string_builder.new()
}
17 changes: 17 additions & 0 deletions src/content/chapter0_basics/lesson14_type_imports/en.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<p>
Other modules may also define types that we wish to refer to. In this case we
need to import them.
</p>
<p>
Like functions types can be referred to in a <em>qualified</em> way by putting
the imported module name and a dot before the type name. For example,
<code>bytes_builder.BytesBuilder</code>
</p>
<p>
Types can also be imported in an <em>unqualified</em> way by listing them in
the import statement with the word <code>type</code> before the type name.
</p>
<p>
It is more common in Gleam code for types to be imported in an unqualified way
than it is for funtions to be imported in an unqualified way.
</p>

0 comments on commit ccf75d2

Please sign in to comment.