Hew
障害を前提とした言語。
Hewはアクターベースのプログラムをネイティブコードにコンパイルします。各アクターは自身の状態を所有し、スーパーバイザーが失敗したアクターの再起動方法を決めます。
状態はアクターの中に留まる
このセッションアクターはメッセージのvectorを所有します。変更できるのはpostだけで、各呼び出しはhandlerが完了してResultを返すまで待ちます。
countは同じ非公開状態を読み、callerに値を返します。呼び出しの完了前にアクターが停止する可能性があるため、エラー分岐も明示されています。
// A chat session is an actor: state lives in fields and only its handlers
// can mutate it. Ordinary actor calls wait for the handler and return a
// Result, whether or not the handler itself returns a value.
actor Session {
let user: string;
var messages: Vec<string> = Vec.new();
receive fn post(text: string) {
messages.push(text);
}
receive fn count() -> i64 {
messages.len()
}
}
fn main() {
let chat = spawn Session { user: "ada", messages: [] };
chat.post("hello").expect("actor stopped");
chat.post("world").expect("actor stopped");
let total = chat.count();
match total {
.Ok(n) => println(f"{n} messages posted"),
.Err(_) => println("session unavailable"),
}
}$ curl -fsSL https://hew.sh/install | bash -s -- --version 0.9.3$ curl -fsSL https://hew.sh/install | bash -s -- --version 0.9.3> Invoke-WebRequest https://hew.sh/install.ps1 -OutFile install.ps1
.\install.ps1 -Version 0.9.3言語が明示するもの
v0.9.3で利用できるアクター、監視、並行処理、ワイヤーの機能です。
- 呼び出し元:
chat.post("hello"). ハンドラーの結果を待つ. - メールボックス:
post("hello"). - 1回のハンドラー実行:
messages.push(text). プライベートな状態:messages: ["hello"]. - 呼び出しの結果 → 呼び出し元.
postが成功すると、Sessionのプライベートな状態を更新してから結果を返します。
アクターの隔離
すべてのアクターが状態を独占的に所有します。コンパイラはローカルアクターの境界とSendチェックを強制します。
監視ツリー
サービスはクラッシュします — Hewはそれを前提とします。スーパーバイザーアクター、再起動バジェット、主要な再起動戦略は別建てのフレームワークではなく、言語自体の一部です。
構造化並行性
scopeは子タスクの範囲を定め、戻る前に完了を待ちます。forkは後で結合できる独立したアクター呼び出しを開始します。
ワイヤーコントラクト
ワイヤー型は、スキーマ・フィールドタグ・互換性チェックを言語そのものに組み込み、それらを送信するアクターと同じ場所で扱えるようにします。
エンジニアリングジャーナル
Hew 0.6.2: safer values, steadier services Edit parsed configuration without changing its source value, then see how Hew 0.6.2 carries the same actor reference across local and remote services. 2026年10月21日ブログを読む → EN
Hew Notes
Language development, engineering articles, releases and community projects. About once a month, with an extra issue for a significant release. Written in English.
Subscribe to Hew Notes