Playground

Bea's compiler, running in your browser. Nothing is sent anywhere.

main.beaTab indents. Esc, then Tab, leaves the editor.
main.gleamGenerated in 1 ms
import gleam/bool
import gleam/float
import gleam/list

pub type Shape {
  Circle(r: Float)
  Rect(w: Float, h: Float)
}

pub fn area(arg_0) {
  case arg_0 {
    Circle(r) -> 3.14 *. r *. r
    Rect(w, h) -> w *. h
  }
}

pub fn describe(shapes: List(Shape)) -> Result(String, String) {
  use <- bool.guard(when: shapes == [], return: Error("no shapes"))
  let total = shapes |> list.map(area) |> float.sum
  Ok("total area: " <> float.to_string(total))
}

pub fn main() {
  describe([Circle(1.0), Rect(2.0, 3.0)]) |> echo
}

The playground turns Bea into Gleam and reports Bea's syntax errors. Type checking and running happen in Gleam, so install Bea to run programs. The compiler here is Bea's own, compiled from its Bea source to JavaScript along with this site.