0 | module Control.Effect.NonDet
2 | import Control.EffectAlgebra
4 | import Control.Monad.List
13 | data ChoiceE : (Type -> Type) -> (Type -> Type) where
14 | Choose : List (Inf (m a)) -> ChoiceE m a
18 | => (f : Functor ctx)
20 | -> Handler ctx n (ListT m)
21 | -> (ChoiceE :+: sig) n a
22 | -> (ListT m) (ctx a)
23 | alg ctxx hdl (Inl (Choose list)) =
26 | go : List (Inf (n a)) -> ListT m (ctx a)
28 | go (x :: xs) = (<+>) @{ListT} (hdl (x <$ ctxx)) (go xs)
29 | alg ctxx hdl (Inr other) =
33 | EffectAlgebra.alg {f = Functor.Compose @{ListM}}
34 | {ctx = ListM m . ctx}
35 | {m} (ctxx :: pure [])
36 | ((~<~) @{%search} @{Functor.ListM} { ctx1 = ListM m
40 | , n = m} f hdl) other
42 | f : Handler (ListM m) (ListT m) m
43 | f = join @{Monad.ListT} . pure
47 | Concat : (al : Algebra sig m) => Algebra (ChoiceE :+: sig) (ListT m)
48 | Concat = MkAlgebra @{Monad.ListT} Algebra.alg
52 | oneOf : Inj ChoiceE sig
57 | send (Choose (map (delay . pure) list))
61 | oneOfM : Inj ChoiceE sig