From f6aa991225e85d32324ed15775ec882dc3b7ecbf Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:26:42 -0300 Subject: [PATCH] modules: add proper example --- src/nix/target/modules.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/nix/target/modules.md b/src/nix/target/modules.md index 750d658..edaaa7a 100644 --- a/src/nix/target/modules.md +++ b/src/nix/target/modules.md @@ -5,7 +5,34 @@ In Gleam, each module corresponds to a single `.gleam` file, and has its own exp When translated to Nix, **each Gleam module becomes a single Nix file.** For example, if your package is named `hello`, the file at `src/my/module.gleam` will generate a file `build/dev/nix/hello/my/module.nix` on build. -Each module file **evaluates to an attribute set containing all exported names.** For example, a module with `pub type Type { Constr(a: Int, b: Int) }`, `pub fn fun()` and `pub const name: Int = 5` will evaluate to an attribute set with attributes `Constr`, `fun` and `name`. +Each module file **evaluates to an attribute set containing all exported names.** + +For example, the module below: + +```gleam +pub type Type { + Constructor(a: Int, b: Int) +} + +pub const constant: Int = 5 + +pub fn name() { + "Hello World!" +} +``` + +transpiles to + +```nix +let + Constructor = a: b: { __gleamTag = "Constructor"; inherit a b; }; + + name = { }: "Hello World!"; + + constant = 5; +in +{ inherit Constructor name constant; } +``` ## Prelude