エラーは型に載る
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 <- Console [10, -4, 7] |> List.map(|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 のない並行処理
タスクは with の項目の中でだけ動き、それを始めた with より長生きしません。
どのターゲットでも同じ結果
JavaScript、WebAssembly、ネイティブの実行ファイルに出力します。Int は32ビットに固定です。