エラーは型に載る
fail で失敗し、escape で受けたいものだけ値に戻します。Result 型も try / catch もありません。
half は Negative で失敗しうると型に書いてあります。main はそのエラーを escape で受けて文字列に戻し、出力します。main の Console は with Platform が供給します。
import Std.Console.{Console}import Std.Platform.{Platform}
error Negative(n: Int)
fn half(n: Int) -> Int fails Negative { if n < 0 { fail Negative(n:) } n / 2}
fn main() { with Platform { console = use Console [10, -4, 7] |> List.map(fn(n) { Int.to_string(half(n)) escape { Negative(n:) -> "#{n} は負" } }) |> String.join(", ") |> console.print_line }}$ emela run main.emel5, -4 は負, 3エラーは型に載る
fail で失敗し、escape で受けたいものだけ値に戻します。Result 型も try / catch もありません。
副作用はエフェクトで
実装は with でハンドラを渡して決まります。テストではハンドラを差し替えます。
await のない並行処理
fiber はスコープの中でだけ動き、スコープより長生きしません。
どのターゲットでも同じ結果
JavaScript、WebAssembly、C に出力します。Int は32ビットに固定です。