flix

0.81.0

Sound

eff SoundSource

Making a noise, as an effect.

The rules say what should be heard and never learn how. The runtime interprets this onto a pool of clips, the tests interpret it into a list, and a machine with no sound card interprets it into nothing -- all three running the identical simulation.

Operations

def play(cmd: SoundCmd): Unit \ Sound§ Source

Definitions

def handleWithCollector(f: a -> b \ ef): SoundCollector[a, b, ef]§ Source

Interprets Sound by recording what was played instead of playing it.

Pure: the accumulator lives in a region that is fully discharged here, so this needs no IO and touches no device. This is what the sound tests use.

def played(f: Unit -> a \ ef): List[SoundCmd] \ ef - Sound§ Source

Runs f and returns only what it played.

def runWithCollector(f: Unit -> a \ ef): (a, List[SoundCmd]) \ ef - Sound§ Source

Runs f, returning its result together with everything it played.

def runWithNoOp(f: Unit -> a \ ef): a \ ef - Sound§ Source

Interprets Sound by discarding it.

Deliberately not a @DefaultHandler, for the same reason as Canvas and Input: a default would not save the callers anything (the effect still has to appear in every @Test signature) and it would let a forgotten interpretation pass unnoticed.

def silent(f: a -> (b -> c)): a -> (b -> c \ Sound)§ Source

Lifts a step that makes no sound into one that is allowed to.

The teaching sketches have nothing to play, but the runtime asks for a step that may. checked_ecast widens the effect without changing behaviour -- the escape hatch the Flix style guide sanctions for exactly this ("if necessary, effect casts are OK").