LEARN VOID / DATA & BEHAVIOR
Interfaces
Describe behavior without tying a function to one struct.
interface readable:
func read() -> i32
interface movable:
func move(amount: i32)
value struct motion:
x: i32
func (m motion) read() -> i32:
return m.x
func (m motion) move(amount: i32):
pass
m.x += amount
pass
struct actor:
using motion
func consume(const r: readable) -> i32:
return r.read()
func entry(value: i32) -> i32:
var a = actor(motion = motion(x = value))
var moving: movable = a
moving.move(4)
const reading: readable = a
return consume(reading) + a.motion.xInput 5Expected result 18
State the required methods
An interface lists the method signatures a value must provide. VOID checks conformance structurally: an implementation supplies compatible methods rather than an implements declaration.
Use a view of the same object
The actor composes a motion value. A movable interface view calls move, and a readonly readable view can call the non-mutating read method. Both views observe the actor’s updated position.
Keep authority visible
A const interface view preserves readonly restrictions. With input 5, moving by 4 gives position 9, and the program returns the two reads added together: 18. Interfaces do not remove visibility or receiver-effect checks.