Skip to content

Std\Channel

Std\Channel — bounded MPMC channels with type-safe sender/receiver split.

channel n returns (Linear (Sender a), Linear (Receiver a)). The linearity checker enforces that each side is unwrapped from Linear exactly once via pattern match. After unwrapping, a Sender a can only send and a Receiver a can only recv / tryRecv, enforcing the producer/consumer split at the type level. Sender and Receiver endpoints implement both Send and Shareable because the runtime channel is synchronized; each transmitted payload must independently implement Send.

See docs/api/Channel.md for the full API.

type Sender a = Sender Channel

Send-only handle wrapping a Channel.

type Receiver a = Receiver Channel

Receive-only handle wrapping a Channel.

channel : Int -> (Linear (Sender value), Linear (Receiver value))

Section titled “channel : Int -> (Linear (Sender value), Linear (Receiver value))”

Compiler-backed constructor. Codegen supplies a hidden payload descriptor after inference has made value concrete.

Create a bounded channel with the given buffer capacity. Returns a tuple of Linear-wrapped sender and receiver handles. The linearity checker requires both wrappers to be unwrapped before scope exit:

let (sl, rl) = channel 16 in
case sl of Linear sender ->
case rl of Linear receiver ->
... -- use sender / receiver freely
end end

Send a value through a sender. Blocks if the buffer is full.

Receive a value. Blocks if the buffer is empty. Returns Some v for a delivered value or None once the channel is closed and drained.

Non-blocking receive — returns immediately even if empty.

Close the sender side. Wakes all blocked sends and recvs.

Returns true if the channel has been closed.

Current number of buffered elements.

Maximum buffer size (set at creation).