Bea's compiler, running in your browser. Nothing is sent anywhere.
main.beaTab indents. Esc, then Tab, leaves the editor.
pubtypeShape {
Circle(r: Float)
Rect(w: Float, h: Float)
}
pubdefarea(Circle(r)) { 3.14*. r *. r }
pubdefarea(Rect(w, h)) { w *. h }
pubdefdescribe(shapes: List(Shape)) ->Result(String, String) {
if shapes == [] {
returnError("noshapes")
}
total = shapes |> list.map(area) |> float.sum
Ok("totalarea:#{float.to_string(total)}")
}
pubdefmain() {
describe([Circle(1.0), Rect(2.0, 3.0)]) |>echo
}
main.gleamGenerated in 1 ms
import gleam/bool
import gleam/float
import gleam/list
pubtypeShape {
Circle(r: Float)
Rect(w: Float, h: Float)
}
pubfnarea(arg_0) {
case arg_0 {
Circle(r) ->3.14*. r *. r
Rect(w, h) -> w *. h
}
}
pubfndescribe(shapes: List(Shape)) ->Result(String, String) {
use<- bool.guard(when: shapes == [], return: Error("noshapes"))
let total = shapes |> list.map(area) |> float.sum
Ok("totalarea:"<> float.to_string(total))
}
pubfnmain() {
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.