aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter5_advanced_features/lesson06_externals/code.gleam
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-03-26 13:57:31 +0000
committerLouis Pilfold <louis@lpil.uk>2024-03-26 13:57:31 +0000
commitc2dcbe0f25a3e8bd60a4ccf377bbdd47f4794871 (patch)
tree18862644ee2dada0a926392b11e606bb0d2262f7 /src/content/chapter5_advanced_features/lesson06_externals/code.gleam
parentccf75d2c362ac8e4dcd12c781f6e1eafd0064813 (diff)
downloadtour-c2dcbe0f25a3e8bd60a4ccf377bbdd47f4794871.tar.gz
tour-c2dcbe0f25a3e8bd60a4ccf377bbdd47f4794871.zip
Document opaque types
Closes https://github.com/gleam-lang/language-tour/issues/63
Diffstat (limited to 'src/content/chapter5_advanced_features/lesson06_externals/code.gleam')
-rw-r--r--src/content/chapter5_advanced_features/lesson06_externals/code.gleam17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/content/chapter5_advanced_features/lesson06_externals/code.gleam b/src/content/chapter5_advanced_features/lesson06_externals/code.gleam
new file mode 100644
index 0000000..1101b82
--- /dev/null
+++ b/src/content/chapter5_advanced_features/lesson06_externals/code.gleam
@@ -0,0 +1,17 @@
+import gleam/io
+
+// A type with no Gleam constructors
+pub type DateTime
+
+// An external function that creates an instance of the type
+@external(javascript, "./my_package_ffi.mjs", "now")
+pub fn now() -> DateTime
+
+// The `now` function in `./my_package_ffi.mjs` looks like this:
+// export function now() {
+// return new Date();
+// }
+
+pub fn main() {
+ io.debug(now())
+}