std.effect.alt

Implementation of the Alt effect

Types

type Alt r a = 
    | Empty
    .. r

The Alt effect lets Eff implement Alternative

Values

#[implicit]
let alternative : forall r . Alternative (Eff [| alt : Alt | r |])

A monoid on applicative functors.

let run_alt eff_1 eff_2 : forall a r .
        Eff [| alt : Alt | r |] a
            -> Eff [| alt : Alt | r |] a
            -> Eff [| | r |] (Option a)

Eliminates the Alt effect returning None if the Alt effect is empty, otherwise returns Some a with the value

let { assert_eq, ? } = import! std.test
let alt @ { ? } = import! std.effect.alt
let state = import! std.effect.state
let { (*>) } = import! std.applicative
let { empty } = import! std.alternative
let { Eff, run_pure, ? } = import! std.effect

let incr = state.modify (\x -> x + 1)

seq assert_eq (run_pure (state.exec_state 0 (alt.run_alt incr incr))) (1)
seq assert_eq (run_pure (state.exec_state 0 (alt.run_alt (incr *> incr) incr))) (2)
seq assert_eq (run_pure (state.exec_state 0 (alt.run_alt (incr *> empty *> incr) incr))) (2)
assert_eq (run_pure (state.exec_state 0 (alt.run_alt empty incr))) (1)