0 | module Control.Eff.Choose
2 | import Control.Eff.Internal
7 | data Choose : (a : Type) -> Type where
9 | Alt : (lft, rgt : a) -> Choose a
12 | empty : Has Choose fs => Eff fs a
16 | alt : Has Choose fs => Eff fs a -> Eff fs a -> Eff fs a
17 | alt x y = join $
send (Alt x y)
20 | guard : Has Choose fs => Bool -> Eff fs ()
22 | guard True = pure ()
30 | {auto _ : Alternative f}
31 | -> {auto _ : Has Choose fs}
33 | -> Eff (fs - Choose) (f a)
34 | runChoose fr = case toView fr of
35 | Pure val => pure (pure val)
36 | Bind x g => case handle (id {a = Choose _}) x of
37 | Left y => assert_total $
lift y >>= runChoose . g
38 | Right Empty => pure empty
39 | Right (Alt lft rgt) => assert_total $
do
40 | x <- runChoose (g lft)
41 | y <- runChoose (g rgt)