import std/io import std/list // A `multi ctl` continuation cannot hold another handler of `ctl` // operations: natively that handler's body runs on a fiber of its own, // which is not copied (ADR 0017). Both backends refuse to resume it. effect amb { multi ctl choose :: -> Bool } effect gen { ctl yield :: x: Int -> () } fn all :: action: fn() -> a / -> List / { handle { [action ()] } with { choose -> list.append (resume True) (resume False) } } fn total :: action: fn() -> () / -> Int / { handle { action () } with { yield x -> x + resume (), return _ -> 0 } } pub fn main :: -> () / { // A generator that finished before `choose` is fine. let fine = all fn { let t = total fn { yield 1 } if choose () { t } else { t + 1 } } io.println ("fine " <> show fine) // One still running when `choose` captures is not. let refused = all fn { total fn { if choose () { yield 1 } else { yield 2 } } } io.println ("not reached " <> show refused) } //> fine [1, 2] //! panic: a `multi ctl` continuation holding a `ctl` handler cannot be resumed