Gleam, a statically typed language for the Erlang VM

Hello all! I’m looking for some feedback on the Gleam HTTP library API. If you’re a twitter users please vote here: https://twitter.com/louispilfold/status/1282272545622970368

If not, reply with a comment, thank you

4 Likes

I prefer the one http module approach, because I personally can’t think of too many times where you’d want to use http requests but not responses. You’d only want requests with no responses when making a http call, and I think it’s a lot more likely that people will use Gleam as an http server rather than an http client. Just my 0.02c, take with a grain of salt, etc.

1 Like

Re:reload in phoenix
I got some sort of reconpiliation/reloading going by adding :gleam as a reloadable compiler in my endpoint config, but currently it recompiles on every http request. :man_shrugging: https://hexdocs.pm/phoenix/Phoenix.CodeReloader.html

1 Like

Not solved but made some progress. Thanks to @michaeljones post https://dev.to/contact-stack/adding-a-custom-watcher-to-phoenix-1e10
I added a chokidar watcher that runs gleam build, which I in turn add to my watchers in the Endpoint configuration in my dev.exs. However the compiled code is not reloaded in the phoenix app it appears.

Note that CodeReloader that I mentioned previously is a plug, and as far as I understand from the docs it’s by design that it reloads code on each request.

1 Like

Gleam v0.11.0-rc1 is out. Please upgrade your projects and give it a try :slight_smile:

https://github.com/gleam-lang/gleam/releases/tag/v0.11.0-rc1

3 Likes

Here’s a random dumb question. Have you (or anybody else in the team) made a thin wrapper around Phoenix in Gleam?

Not a dumb question at all!

Currently Gleam has a HTTP library and a Plug adapter that will allow you to call Gleam HTTP service modules from Plug applications (such as Phoenix). I’ll be writing more about this with the comining release but you may be able to get something going with the READMEs + hexdocs for now:


Here’s what usage might look like:

Define a Gleam service module

import gleam/http
import gleam/bit_builder.{BitBuilder}

pub fn service(req: http.Request(BitBuilder)) {
  http.response(200)
  |> http.prepend_resp_header("made-with", "Gleam")
  |> http.set_resp_body(req.body)
}

Call it from Elixir

defmodule MyAppWeb.UserController do
  use MyAppWeb, :controller

  def show(conn, params) do
    conn
    |> GleamPlug.call_service(params, &:my_gleam_module.service/1)
  end
end
8 Likes

This is exciting! I was checking in on Midas from time to time but the repository seems quite quiet which is perfectly understandable. I need to keep an eye on the wider gleam repositories it seems :slight_smile:

Indeed it is. Most of the first version of midas found a home in other places. Quick summary if you like

  1. I’ve been trying to contribute what is appropriate to gleam_http. This has included cookies.
  2. For Midas Lean server I am watching how gleam_otp goes, at the moment it has it’s own wrappers around spawning etc. In the meantime I am using the cowboy wrapper.
  3. Other things I need have appeared in libraries, such as gleam_json and this PR on gleam_pgo https://github.com/gleam-experiments/pgo/pull/4
  4. That leaves midas basically only a libary for neatly specifying form casting, which I do like and am using.

Midas is definitely not off my radar, just I think it will now more usefully be the conventions that bring together the things listed above

5 Likes

Gleam v0.11.0 is out! As per usual I’ve made a post giving an overview of what’s new. Check it out here -> https://lpil.uk/blog/gleam-v0.11-released/

One thing I think people will find interesting here is the support for embedding Gleam HTTP services inside Elixir Plug apps.

6 Likes

I’m really happy to see that 0.11.0 includes a more elegant way of updating records!
Good work everyone involved

2 Likes

Hey folks, I’ve written a little Elixir site to pull together the Github activity feeds from various Gleam repositories and show them all on one timeline. It is basic but quite useful for scanning recent activity.

https://dashboard.michaelpjones.co.uk/gleam

There is also a /elm which covers various elm community repositories. There repos are hard coded but the code is open source so you can easily suggest more and I can deploy it quite easily. Also welcome to improve the layout or highlight some things more. I reduced the visual display of the commits as they get quite noisy and I’ve just added a button to hide all comments as they can be overwhelming too. There might be plenty of other improvements though. I’ve also no expert designer. I’ve attempted to make it work on mobile and I’ve enjoyed using Tailwind on it. Not used it for that much before.

I think it might be quite interesting to have a version that can also include notable tweets or blog posts or other events from a community which could then be categorised into various levels so that you could see a high level year by year overview or a more detailed catch up of the last few months or a very thorough update on the last week.

4 Likes

Is there an LSP project yet?

No, not yet. It is on the backlog though.

1 Like

Hi, can i specify subtype as function argument type or return type, list element type ?I tried something like example below, but i got a compilation error

pub opaque type Cart {
    Empty
    NonEmpty
}

pub fn new() -> Empty {
    todo
}

pub fn checkout(cart: NonEmpty) -> Int {
    todo
}
1 Like

I don’t know anything about Gleam but can you really use only one type from discriminated union like that because it looks wrong? Are you sure checkout functions type shouldn’t be type Cart instead of NonEmpty?

1 Like

Hi @arturs678! Thanks for trying out Gleam!

Gleam doesn’t have any form of subtyping, so Empty and NonEmpty only have a single type, and that type is Cart. Empty and NonEmpty are values, not types.

As @wanton7 says the type annotations will need to be changed to Cart and then the code you’ve given will compile.

pub opaque type Cart {
  Empty
  NonEmpty
}

pub fn new() -> Cart {
  Empty
}

pub fn checkout(cart: Cart) -> Int {
  todo
}
2 Likes

Quinn Wilton’s ElixirConf talk is up!

ElixirConf 2020 - Type-Safe LiveView with Gleam - Quinn Wilton

5 Likes

Maybe you actually want to do something like this:

pub opaque type Cart {
  EmptyCart
  NonEmptyCart(info: CartInfo)
}

pub opaque type CartContents {
  CartContents(
    products: List(Product)
    // And maybe other fields
    )
}

Now you can have functions that require a filled cart as input or output work directly on CartContents, and have functions that should also work for empty carts use the Cart wrapper type.

2 Likes

Hi everyone!

In order to make the Gleam community a bit more accessible we’re moving from IRC to Discord. It’s easier to use, saves chat history for people to read back over, and has anti-harassment features (which hopefully we won’t need), so overall it’s a big improvement.

Please join using this link here -> https://discord.gg/Fm8Pwmy :sparkles:

Thanks!

9 Likes