// `std/dist`'s typing roots (ADR 0072): a `Name` exists only for a // message type that can cross hosts, `register` and `whereis` keep the // subject's type the name's, and `spawn_on`'s argument is its `@remote` // function's. import std/dist.{type DistError, type Name, type Remote} import std/process.{type Pid, type Subject, type proc} type Counter { Add(Int), Get(Subject) } type Job { Job(run: fn() -> Int) } fn named :: -> Name { dist.name "counter" } fn a_function_cannot_cross :: -> Name ()> { dist.name "f" //~ ERROR E0706 a function's code } fn nor_a_field_of_one :: -> Name { dist.name "job" //~^ ERROR E0706 `Job` has a field `run` that cannot cross hosts } fn nor_a_reply_of_one :: -> Name ()>> { dist.name "replies" //~^ ERROR E0706 a `Subject`'s messages must cross hosts too } fn registered :: s: Subject -> Result<(), DistError> / { dist.register (named ()) s } fn of_another_type :: s: Subject -> Result<(), DistError> / { dist.register (named ()) s //~ ERROR E0202 expected `Subject`, found `Subject` } fn found :: -> Result, DistError> / { dist.whereis (named ()) "node-b.cluster.example" 1000 } // The name is opaque: only `dist.name` makes one. fn forged :: -> Name { dist.Name("counter") //~ ERROR E0117 `Name` is opaque } @remote fn worker :: counter: Subject -> () / { process.send counter Add(1) } fn spawned :: c: Subject -> Result / { dist.spawn_on "node-b.cluster.example" worker c 1000 } //~ TYPE spawned: fn(Subject) -> Result / // `dist.Remote` is `std/dist/remote`'s. fn entry :: -> Remote> { worker } fn with_another_argument :: -> Result / { dist.spawn_on "node-b.cluster.example" worker 42 1000 //~^ ERROR E0202 expected `Subject`, found `Int` } fn through_a_reference :: c: Subject -> Result / { dist.spawn_on "node-b.cluster.example" (entry ()) c 1000 //~^ ERROR E0202 expected `Subject`, found `Subject` }