Gleam is a functional programming language implemented in Rust, built on the Erlang virtual machine, compiled to Erlang (or JavaScript), supports interoperability with other BEAM languages ​​(such as Erlang, Elixir and LFE), mainlyFor building type-safe, scalable systems.

characteristic

  • Actor-based multi-core concurrency
  • Algebraic data types
  • Erlang-style fault tolerance
  • fast compilation
  • full type inference
  • Generics
  • useful error messages
  • immutable data structure
  • No exception by default
  • no null
  • no undefined behavior
  • Reliable package management
  • Small but consistent language design
  • Zero-cost interop with Erlang, Elixir, and more

sample code

Hello, World!


import gleam/io

pub fn main() {
  io.println("Hello, world!")
}

Simple Web Server


import gleam/io
import gleam/bit_builder
import gleam/http/elli
import gleam/http/response

pub fn my_service(_req) {
  let body = bit_builder.from_string("Hello, world!")

  response.new(200)
  |> response.set_body(body)
}

pub fn main() {
  elli.become(my_service, on_port: 3000)
}

multithreaded hello world


import gleam/io
import gleam/int
import gleam/list
import gleam/string
import gleam/otp/process

pub fn main() {
  list.range(0, 1000)
  |> list.map(start_process)
  |> list.map(process.monitor_process)
  |> list.each(process.receive(_, 3)) // Wait for them to finish
}

fn start_process(i) {
  process.start(fn() {
    let message = string.append("Hello world: ", int.to_string(i))
    io.println(message)
  })
}

#Gleam #Lang #Homepage #Documentation #Downloads #Functional #Programming #Language #Implemented #Rust #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *