Skip to content

Commit

Permalink
modules: add proper example
Browse files Browse the repository at this point in the history
  • Loading branch information
PgBiel committed Apr 23, 2024
1 parent 227b282 commit f6aa991
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/nix/target/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f6aa991

Please sign in to comment.