./lang/gleam, ML-flavoured type-safe language using the BEAM runtime

[ CVSweb ] [ Homepage ] [ RSS ] [ Required by ] [ Add to tracker ]


Branch: CURRENT, Version: 0.30.4, Package name: gleam-0.30.4, Maintainer: pkgsrc-users

Gleam is a functional language for building type-safe, scalable
systems.

The Gleam compiler itself is written in rust.

Gleam uses the BEAM runtime, and using the same actor-based multi-core
concurrency, with zero runtime overhead and full inter-operability
with Erlang, Elixir, and LFE.

It has all the features you'd expect from an ML derived language,
including algebraic data-types, immutable data structures, full type
inference, fast compilation, generics, no nulls nor exceptions, and a
few bonus features such as helpful error messages.


Master sites:


Version history: (Expand)


CVS history: (Expand)


   2023-07-30 22:27:59 by nikita | Files touched by this commit (3) | Package updated
Log message:
gleam: update to version 0.30.4

Changelog:

## v0.30.4 - 2023-07-26

- External implementations are always referenced directly in generated code, to
  avoid the overhead of an extra function call.
- Fixed a bug where the compiler could infer incorrect generic type parameters
  when analysing a module without type annotations with self recursive
  functions that reference themselves multiple times.

## v0.30.3 - 2023-07-23

- Fixed a bug where JavaScript module path such as `node:fs` would be rejected.
- New Gleam projects are created with `gleam_stdlib` v0.30, Erlang OTP v26.0.2,
  Elixir v1.15.4, actions/checkout v3.5.1, and erlef/setup-beam v1.16.0.

## v0.30.2 - 2023-07-20

- Fixed a bug where the compiler could infer incorrect generic type parameters
  when analysing a module without type annotations with self recursive
  functions.
- Fixed a bug where the formatter would incorrectly format external functions
  by breaking the return annotation instead of the function arguments.

## v0.30.1 - 2023-07-13

- Fixed a bug where the language server could fail to import path dependencies
  in monorepos.

## v0.30.0 - 2023-07-12

- A warning is now emitted for the deprecated external fn syntax.

## v0.30.0-rc4 - 2023-07-10

- An error is now emitted for invalid JavaScript external implementations.
- Fixed a bug where Erlang external implementations could generate invalid code.

## v0.30.0-rc3 - 2023-07-05

- Fixed a bug where `gleam fix` would fail to parse command line flags.

## v0.30.0-rc2 - 2023-07-03

- Fixed a bug where `gleam fix` would merge external functions of the same name
  but incompatible types.
- Fixed a bug where external function arguments would incorrectly be marked as
  unused.

## v0.30.0-rc1 - 2023-06-29

- The new `@target(erlang)` and `@target(javascript)` attribute syntax has been
  added for conditional compilation. The existing `if` conditional compilation
  syntax has been deprecated. Run `gleam fix` to update your code.
- The new `type TypeName` syntax syntax replaces the `external type TypeName`
  syntax. The existing external type syntax has been deprecated. Run `gleam format`
  to update your code.
- Adding a new dependency now unlocks the target package. This helps avoid
  failing to find a suitable version for the package due to already being
  locked.
- A custom message can now be specified for `panic` with `panic as "..."`.
- The syntax for specifying a custom message for `todo` is now `todo as \ 
"..."`.
- The Erlang error raised by `let assert` is now tagged `let_assert`.
- Types named `Dynamic` are now called `dynamic_` in Erlang to avoid a clash
  with the new Erlang `dynamic` type introduced in OTP26.
- Dependencies can now be loaded from paths using the
  `packagename = { path = "..." }` syntax in `gleam.toml`.
- The `javascript.deno.unstable` field in `gleam.toml` can now be used to
  enable Deno's unstable APIs when targeting JavaScript.
- Blockquotes are now styled in rendered HTML documentation.
- The `gleam` property can be set in `gleam.toml` can be set to a version
  requirement to specify the version of Gleam required to build the project.
- Type aliases can now refer to type aliases defined later in the same module.
- Fixed a bug where unapplied record constructors in constant expressions would
  generate invalid Erlang.
- Fixed a bug where the prescedence of `<>` and `|>` would clash.
- Fixed a bug where `gleam docs build` would print an incorrect path upon
  completion.
- Warnings from dependency packages are no longer surfaced in the language
  server.
- A warning is now emitted when a Gleam file is found with an invalid name.
- A warning is now emitted when using `list.length` to check for the empty list,
  which is slow compared to checking for equality or pattern matching (#2180).
- The new `gleam remove <package_name>` can be used to remove dependencies
  from a Gleam project.
- Fixed a bug where the formatter could crash.
- Fixed a bug where invalid Erlang would be generated when piping into `panic`.
- The `gleam docs build` command gains the `--open` flag to open the docs after
  they are generated (#2188).
- Fixed a bug where type annotations for constants could not be written with
  type annotations.
- Updated font loading in generated HTML documentation to fix an issue with
  fonts not loading properly in some browsers (#2209).

## v0.29.0 - 2023-05-23

- New projects now require `gleam_stdlib` v0.29.

## v0.29.0-rc2 - 2023-05-22

- The `gleam lsp` command is no longer hidden from the help output.
- Fixed a bug where some language server clients would show autocompletion
  suggestions too eagerly.

## v0.29.0-rc1 - 2023-05-16

- The language server will now provide autocomplete suggestions for types and
  values either imported or defined at the top level of the current module.
- Fixed a bug where record patterns using the spread operator (`..`) to discard
  unwanted arguments would not type check correctly when the record had no
  labelled fields.
- Add support for using sized binary segments in pattern matches when targeting
  JavaScript.
- A warning is now emitted for double unary negation on ints (`--`) and bools
  (`!!`) as this does nothing but return the original value.
- Previously the build tool would discard the entire build directory when \ 
dependencies
  were changed. Now it will only discard the build artefacts for removed
  dependencies.
- The errors emitted when a name is reused in a module have been made clearer.
- Fixed an incorrect URL in the error message for failing to parse a let binding
  with a type annotation.
- Fixed a bug where shadowing a prelude type name could result in incorrect
  errors in exhaustiveness checking.
- Fixed a bug where the language server would in some scenarios not remove an
  error diagnostic after it becomes outdated.
- Fixed a bug where the formatter would incorrectly format blocks with a comment
  before them that were the only argument to a function call.
- Fixed a bug where the language server would not reset the build directory when
  it was created by a different version of Gleam.
- New Gleam projects are created with `erlef/setup-beam@v1.15.4` in their GitHub
  actions CI configuration.
- Running a module now uses the dependency's target and runtime in its `gleam.toml`.
   2023-04-17 17:59:41 by Nikita | Files touched by this commit (3)
Log message:
gleam: Update to version 0.28.3

Changelog:

v0.28.3 - 2023-04-17

    Fixed a bug where the language server would show outdated error diagnostics \ 
when a new one was emitted in a different module.
    Fixed a bug where the language server would attempt to analyse Gleam modules \ 
that were outside of the src or test directories.
    New Gleam projects are created with actions/checkout@v3.5.1 and \ 
erlef/setup-beam@1.15.3 in their GitHub actions CI configuration.

v0.28.2 - 2023-04-10

    Fixed a bug where comments above a use expression would be formatted incorrectly.
    Fixed a bug where the formatter would fail to preserve empty lines after a block.
    Fixed a bug where the formatter would fail to preserve empty lines after an \ 
anonymous function with a return annotation.
   2023-04-06 02:26:07 by Nikita | Files touched by this commit (2) | Package updated
Log message:
gleam: update to version 0.28.1

Changelog:

## v0.28.1 - 2023-04-05

- Fixed a bug where the languag server would unset too many error diagnostics
  when multiple projects are open, more than one have errors, and one of them is
  successfully compiled.
- Fixed a bug where the language server would unset error diagnostics when
  displaying information on hover.
   2023-04-03 21:58:03 by Nikita | Files touched by this commit (3)
Log message:
gleam: Update to version 0.28.0

Changelog:
taken from https://github.com/gleam-lang/gleam/blob/main/CHANGELOG.md,
more at https://gleam.run/news/v0.28-monorepos-fast-maps-and-more/

v0.28.0 - 2023-04-03

    New projects now require gleam_stdlib v0.28.

v0.28.0-rc3 - 2023-03-31

    Fixed a bug where source links would be incorrect in HTML documentation.

v0.28.0-rc2 - 2023-03-27

    Fixed a bug where single statement blocks inside binary operators could \ 
generate invalid JavaScript.
    Fixed a bug where the formatter could incorrectly place comments.
    Fixed a bug where the language server would show outdated diagnostics when a \ 
file with an error reverts to the previous valid version, causing the compiler \ 
to use the cached version of the file.

v0.28.0-rc1 - 2023-03-26

    The language server now analyzes files on edit rather than on save, \ 
providing feedback faster.
    The language server now supports editor sessions that span multiple \ 
projects. This is useful for mono-repos and projects with both a frontend and \ 
backend in Gleam.
    The language server now also shows documentation on hover for expressions.
    The language server now shows types and documentation on hover for patterns.
    Added support for negation of integers with the new - unary operator.
    Variable assignments are now only permitted within a function or a block, \ 
not anywhere that an expression is permitted.
    The deprecated try expression has been removed.
    The deprecated assert ... = ... syntax has been removed.
    Semicolons are no longer whitespace. An error will be emitted if one is \ 
encountered.
    Warnings are now immediately emitted rather than being buffered until the \ 
end of the compilation.
    The --warnings-as-errors flag is now supported by gleam build.
    Blocks are now preserved by the formatter when they only have a single \ 
expression within them.
    Generated docs now export more meta data to improve the developer \ 
experience, accessibility and search engine discoverability.
    Files are now only recompiled if they have changed since the last \ 
compilation, detected by file hash and modification time. Previously only the \ 
modification time was used.
    Autocompletion of module imports was removed due to a buggy implementation.
    Fixed a bug where the formatter would incorrectly remove { ... } from bit \ 
string segment value expressions.
    Fixed a bug where TypeScript type definitions files could include incorrect \ 
type names.
    Fixed a bug where the compiler used VSCode specific behaviour in the \ 
language server which was incompatible with Helix.
    Fixed a bug where string concatenation patterns on strings with escape \ 
characters would generate javascript code with wrong slice index.
    Fixed a bug where blocks could parse incorrectly.
    Allow modules to be run with the gleam run --module command.
   2023-03-02 19:53:57 by Nikita | Files touched by this commit (3) | Package updated
Log message:
gleam: update to version 0.27.0

ChangeLog (taken from https://gleam.run/news/v0.27-hello-panic-goodbye-try/):

Gleam is a type safe and scalable language for the Erlang virtual machine and \ 
JavaScript runtimes. Today Gleam v0.27.0 has been released, let’s take a look \ 
at what’s new.
Using patterns in use expressions

The Gleam v0.25 release introduced the use expression, a feature that helps \ 
avoid “callback hell” in Gleam programs. It is quite powerful and can be \ 
used to emulate many features found in other languages such as early returns, \ 
list comprehensions, async/await, monadic do syntax, and more!

pub fn handle(req: Request) -> Response {
  // Return an error for non-post requests
  use <- when(req.method != Post, return: method_not_allowed)

  // Parse the request body or return an error
  use json <- require_json_body(req)

  // Open a database connection, closing it when we're done
  use conn <- database.with_connection

  case database.insert(conn, json) {
    Ok(record) -> created_response(record)
    Error(err) -> bad_request_response(err)
  }
}

One limitation of the use expression was that patterns could not be used with \ 
their assignments, only bare variables. This means you could not destructure a \ 
tuple or other data structure with them.

As of this release patterns are now supported in the use expression, for all \ 
your destructuring needs!

use #(first, second) <- some_tuple_function()

Don’t Panic!

This release introduces the panic keyword, a simple little keyword that causes \ 
the program to crash. Why would you want to do this?

Your program may not have sufficiently constrainted types to make invalid state \ 
unrepresentable. In this case you may want to use panic to crash the program \ 
when an invalid state is reached, which is often preferable than silently \ 
continuing or programming defensively.

Alternatively you may be embracing the Erlang philosophy of “let it crash” \ 
and choosing to use handle unexpected exceptional errors with an Erlang style \ 
supervision tree. This strategy is particularly effective when rapidly \ 
prototyping or in situations where there is no way to reasonably recover from an \ 
error, or client to show an error message to.

case this_should_never_fail() {
  Ok(value) -> continue(value)

  // Oh no! Something went horribly wrong!
  Error(_) -> panic
}

Panic is similar to the assert keyword, only it always crashes rather than \ 
conditionally. Speaking of the assert keyword…
Towards a better assert

Gleam’s assert keyword is used to ensure that data matches a given pattern, \ 
crashing the program if it does not. This is useful, but using assert for this \ 
functionality means that we can’t have an assert feature that works with \ 
boolean expressions, as is commonly found in other languages.

To remedy this the pattern matching feature has been moved to this let assert \ 
syntax. The existing assert keyword has been deprecated and will later be used \ 
for a more conventional assertion feature, to be part of a larger Gleam \ 
milestone based around improving the ergonomics of testing Gleam code.

let assert Ok(value) = this_should_never_fail()

Deprecations are annoying, and nobody likes having to fix their code, so the \ 
Gleam tooling will automatically upgrade your syntax when you run gleam format \ 
or format the code in your editor.
Moving beyond try

try expressions were introduced way back in v0.9 as a way of avoiding callback \ 
hell when working with functions that can either return a value or an error. Now \ 
that we have use expressions, the less general try expressions are redundant. We \ 
always prefer to have fewer ways to do the same thing in Gleam, and fewer things \ 
to have to learn, so try expressions are deprecated in this release.

A try expression can be replaced by a use expression with the then function from \ 
the gleam/result module. Once try is no longer a keyword the then function will \ 
be aliased to try.

// With try
try file = open_file()

// With use
use file <- then(open_file())

// After `try` is removed
use file <- try(open_file())

This is still annoying to fix by hand, so the new gleam fix command has been \ 
created to automatically upgrade your code for you.

And that’s it! There’s also lots of other small improvements and bug fixes, \ 
so check the full release notes for more details.

Thanks

Gleam is made possible by the support of all the kind people and companies who \ 
have very generously sponsored or contributed to the project. Thank you all!

If you like Gleam consider sponsoring or asking your employer to sponsor Gleam \ 
development. I work full time on Gleam and your kind sponsorship is how I pay my \ 
bills!

    Fly
   2023-01-19 20:26:55 by Nikita | Files touched by this commit (3) | Package updated
Log message:
gleam: update to version 0.26

ChangeLog taken from https://gleam.run/news/v0.26-incremental-compilation-and-deno/
Incremental compilation, and hello Deno!

Gleam v0.26 released

Incremental compilation

A Gleam project is made of packages, typically a top level package and several
dependency packages fetched by the package manager, and each package contains
a collection of modules of Gleam code.

In the very early days of Gleam when the compiler was run it would compile from
scratch every module in every package in the project. This was highly wasteful,
especially for the dependency packages which are would not have changed at all.
To tackle this inefficiency when the Gleam build tool was created it was made
to compile dependency packages only once and reuse the compiled code for every
following build, resulting in only the top level package being recompiled.

This has worked well for the last couple years, but now as more people are
using Gleam it was time for an upgrade. Large projects such as those with a
large amount of generated gRPC code were starting to take an irksome amount of
time to compile. Gleam is all about fun and productivity, so this just won't do!

There are numerous ways we want to improve the performance of the (already
very nimble) Gleam compiler, but the majority of the time is spent in the Erlang
compiler, which we use to generate BEAM bytecode, so these improvements will not
be very impactful here. Instead we need to improve the build tool such that it
only compiles modules when it has to, rather than the entire package.

To benchmark the impact of this change I created a Gleam package with 300,000
lines of code and 370,000 lines of documentation comments across 1400 modules,
and test recompiling the package without any changes. The old version of the
compiler will recompile every module, while the new version will instead only
read and verify the caches.
Erlang

Benchmark 1: v0.25
  Time (mean ± σ):     18.443 s ±  0.949 s    [User: 18.458 s, System: 2.995 s]
  Range (min … max):   17.102 s … 19.968 s    10 runs

Benchmark 2: v0.26
  Time (mean ± σ):     140.8 ms ±   3.9 ms    [User: 92.5 ms, System: 46.4 ms]
  Range (min … max):   138.0 ms … 156.1 ms    20 runs

Summary
  'v0.26' ran
  130.99 ± 7.67 times faster than 'v0.25'

When targeting Erlang rebuilding now 130 times faster than before for a
project this size!
JavaScript

Benchmark 1: v0.25
  Time (mean ± σ):      1.861 s ±  0.026 s    [User: 1.543 s, System: 0.299 s]
  Range (min … max):    1.833 s …  1.927 s    10 runs

Benchmark 2: v0.26
  Time (mean ± σ):     145.3 ms ±   2.9 ms    [User: 92.9 ms, System: 50.8 ms]
  Range (min … max):   141.4 ms … 154.3 ms    20 runs

Summary
  'v0.26' ran
   12.81 ± 0.31 times faster than 'v0.25'

When targeting JavaScript the change is less impactful, running just under 13
times faster. This is because on this target we don't need to run the Erlang
compiler to generate bytecode, the outputted JavaScript code can be loaded
directly into a JavaScript runtime.

These benchmarks were performed with the excellent Hypefine command line
benchmarking tool.
How does it work?

When the compiler runs for each module it emits a set of reusable artefacts:

    Erlang bytecode in a .beam file.
    Erlang record definitions in .hrl files for use by any native Erlang modules.
    Information on the types and values in the module in a .cache file.
    Information the compilation of the module in a .cache_meta file.

If the module doesn't need to be compiled again then we can load the .beam
bytecode into the virtual machine, load the module information from the .cache
file so we can compile other modules that depend on it, and move on to the next
module.

How do we tell if a module needs to be recomplied? There are two checks we need
to make, both using information stored in the .cache_meta file.

The first is to check the modification time of the source file against the
compile time stored in the .cache_meta file. If the source file modification
time is newer then it has been changed and we need to recompile it.

The second is to look at the modules dependencies. The .cache_meta file stores
a list of the modules the the module imports, and using this we can tell if any
of modules upstream in the dependency tree are going to be recompiled. If so
then we need to recompile the module as a change in a dependency may mean that
this module needs to be compiled differently than last time.

What's next?

These changes have made a huge difference to compilation speed, but there's
still a lot more easy wins we can apply in future here if the need arises such
as improvements to the efficiency of the compiler's IRs, more precise cache
invalidation, and multithreaded compilation.

Developer experience is a top priority for Gleam. You need your feedback as
quickly as possible when writing Gleam code, so we're committed to keeping the
compiler super speedy.

Running on Deno

Gleam can run on JavaScript as well as the Erlang virtual machine. Until now
when you run gleam run or gleam test with a Gleam project targeting JavaScript
it'll run your code using the NodeJS runtime. With v0.26 the Deno runtime can
be used instead!

Deno is similar to NodeJS in many ways, but it boasts better compliance with
web-standard APIs, much better security, and a very slick developer experience.

To use Deno instead of NodeJS you can either add the --runtime=deno flag to
commands like gleam run, or you can add the javascript.runtime property to your
gleam.toml file.

name = "my_project"
version = "1.0.0"

[javascript]
runtime = "deno"

Thank you to Brett Kolodny for this feature!
Thanks

Gleam is made possible by the support of all the kind people and companies who
have very generously sponsored or contributed to the project. Thank you all!

If you like Gleam consider sponsoring or asking your employer to sponsor Gleam
development. I work full time on Gleam and your kind sponsorship is how I pay
my bills!
   2023-01-17 19:22:32 by Nikita | Files touched by this commit (2)
Log message:
gleam: Update to version 0.25.3

Changelog
v0.25.3 - 2022-12-16

    4 digit integers are no longer automatically formatted with underscores.

v0.25.2 - 2022-12-16

    Updated actions/checkout from actions/checkout@v3.0.0 to @v3.2.0 for
    projects created via gleam new.
    Fixed a bug where gleam new would set a Rebar3 version to 25.1 instead of
    the latest stable 3.
    Updated following runtime versions set via gleam new: Erlang/OTP to 25.2,
    and Elixir to 1.14.2.
    The formatter now inserts underscores into larger Ints and the larger
    integer parts of Floats.
    Added support for top level TypeScript file inclusion in builds.
    The build tool will now favour using rebar3 over Mix for packages that
    support both. This fixes an issue where some packages could not be compiled
    without Elixir installed even though it is not strictly required.

v0.25.1 - 2022-12-11

    New Gleam projects are now configured to explicitly install rebar3 using
    GitHub actions erlef/setup-beam.
    A better error message is now shown when attempting to use a function
    within a constant expression.
    Changed float size limit in bitstring expressions to 16, 32 or 64, when
    static. Also allowed dynamic size.
    New Gleam projects are created using GitHub actions
    erlef/setup-beam@v1.15.0.
    Fixed a bug where returning an anonymous function from a pipeline an
    dcalling it immediately without assigning it to a variable would produce
    invalid Erlang code.
    Fixed a bug where the formatter would remove the braces from negating
    boolean expressions.
   2022-12-14 19:01:41 by Nikita | Files touched by this commit (3) | Package updated
Log message:
lang/gleam: update to version 0.25.1

Changelog (taken from https://github.com/gleam-lang/gleam/blob/main/CHANGELOG.md)

v0.25.1 - 2022-12-11
- New Gleam projects are now configured to explicitly install rebar3 using
  GitHub actions erlef/setup-beam.
- A better error message is now shown when attempting to use a function within a
  constant expression.
- Changed float size limit in bitstring expressions to 16, 32 or 64, when static.
  Also allowed dynamic size.
- New Gleam projects are created using GitHub actions erlef/setup-beam@v1.15.0.
- Fixed a bug where returning an anonymous function from a pipeline and calling
  it immediately without assigning it to a variable would produce invalid Erlang
  code.
- Fixed a bug where the formatter would remove the braces from negating boolean
  expressions.

v0.25.0 - 2022-11-24

v0.25.0-rc2 - 2022-11-23
- Fixed a bug where Gleam dependency packages with a `priv` directory could fail
  to build.
- Fixed a regression where Elixir and Erlang Markdown code blocks in generated
  documentation would not be highlighted.

v0.25.0-rc1 - 2022-11-19
- Generated HTML documentation now includes the `theme-color` HTML meta tag.
- The `use` expression has been introduced. This is a new syntactic sugar that
  permits callback using code to be written without indentation.
- Nightly builds are now also published as OCI container images hosted on
  GitHub.
- Fixed a bug where the build tool would not hook up stdin for Gleam programs it
  starts.
- Fixed a bug where using a record constructor as a value could generate a
  warning in Erlang.
- Fixed a bug where the build tool would use precompiled code from Hex packages
  rather than the latest version, which could result in incorrect external
  function usage in some cases.
- Fixed a bug where the warning for `todo` would not print the type of the code
  to complete.
- Fixed a bug where `try` expressions inside blocks could generate incorrect
  JavaScript.
- Generated HTML documentation now includes all static assets (but the web
  fonts), so that it can be accessed offline or in far future once CDNs would
  404.
- New Gleam projects are created using GitHub actions erlef/setup-beam@v1.14.0
- The `javascript.typescript_declarations` field in `gleam.toml` now applies to
  the entire project rather than just the top level package.
- The formatter now adds a 0 to floats ending with `.` (ie 1. => 1.0).
- New projects require `gleam_stdlib` v0.25.