{-# OPTIONS_HADDOCK not-home #-}
module Control.Effect.Internal.NonDet where

import Data.Coerce

import Control.Effect
import Control.Effect.Carrier

import Control.Effect.Type.Split
import Control.Effect.Type.Regional

import Control.Effect.Internal.Utils


import qualified Control.Monad.Trans.List.Church as L

-- | An effect for nondeterministic computations
newtype NonDet :: Effect where
  FromList :: [a] -> NonDet m a

-- | An effect for culling nondeterministic computations.
newtype Cull :: Effect where
  Cull :: m a -> Cull m a

-- | An effect to delimit backtracking within nondeterministic contexts.
data Cut :: Effect where
  Cutfail :: Cut m a
  Call    :: m a -> Cut m a

-- | A pseudo-effect for connected 'NonDet', 'Cull', 'Cut', and 'Split' effects.
--
-- @'Logic'@ should only ever be used inside of 'Eff' and 'Effs'
-- constraints. It is not a real effect! See 'Bundle'.
type Logic = Bundle '[NonDet, Cull, Cut, Split]


-- | 'NonDetThreads' accepts the following primitive effects:
--
-- * 'Control.Effect.Regional.Regional' @s@
-- * 'Control.Effect.Optional.Optional' @s@ (when @s@ is a functor)
-- * 'Control.Effect.Type.Unravel.Unravel' @p@
-- * 'Control.Effect.Type.ListenPrim.ListenPrim' @o@ (when @o@ is a 'Monoid')
-- * 'Control.Effect.Type.WriterPrim.WriterPrim' @o@ (when @o@ is a 'Monoid')
-- * 'Control.Effect.Type.ReaderPrim.ReaderPrim' @i@
type NonDetThreads = Threads L.ListT

newtype LogicC m a = LogicC { LogicC m a -> ListT m a
unLogicC :: L.ListT m a }
  deriving ( a -> LogicC m b -> LogicC m a
(a -> b) -> LogicC m a -> LogicC m b
(forall a b. (a -> b) -> LogicC m a -> LogicC m b)
-> (forall a b. a -> LogicC m b -> LogicC m a)
-> Functor (LogicC m)
forall a b. a -> LogicC m b -> LogicC m a
forall a b. (a -> b) -> LogicC m a -> LogicC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (m :: * -> *) a b. a -> LogicC m b -> LogicC m a
forall (m :: * -> *) a b. (a -> b) -> LogicC m a -> LogicC m b
<$ :: a -> LogicC m b -> LogicC m a
$c<$ :: forall (m :: * -> *) a b. a -> LogicC m b -> LogicC m a
fmap :: (a -> b) -> LogicC m a -> LogicC m b
$cfmap :: forall (m :: * -> *) a b. (a -> b) -> LogicC m a -> LogicC m b
Functor, Functor (LogicC m)
a -> LogicC m a
Functor (LogicC m)
-> (forall a. a -> LogicC m a)
-> (forall a b. LogicC m (a -> b) -> LogicC m a -> LogicC m b)
-> (forall a b c.
    (a -> b -> c) -> LogicC m a -> LogicC m b -> LogicC m c)
-> (forall a b. LogicC m a -> LogicC m b -> LogicC m b)
-> (forall a b. LogicC m a -> LogicC m b -> LogicC m a)
-> Applicative (LogicC m)
LogicC m a -> LogicC m b -> LogicC m b
LogicC m a -> LogicC m b -> LogicC m a
LogicC m (a -> b) -> LogicC m a -> LogicC m b
(a -> b -> c) -> LogicC m a -> LogicC m b -> LogicC m c
forall a. a -> LogicC m a
forall a b. LogicC m a -> LogicC m b -> LogicC m a
forall a b. LogicC m a -> LogicC m b -> LogicC m b
forall a b. LogicC m (a -> b) -> LogicC m a -> LogicC m b
forall a b c.
(a -> b -> c) -> LogicC m a -> LogicC m b -> LogicC m c
forall (m :: * -> *). Functor (LogicC m)
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *) a. a -> LogicC m a
forall (m :: * -> *) a b. LogicC m a -> LogicC m b -> LogicC m a
forall (m :: * -> *) a b. LogicC m a -> LogicC m b -> LogicC m b
forall (m :: * -> *) a b.
LogicC m (a -> b) -> LogicC m a -> LogicC m b
forall (m :: * -> *) a b c.
(a -> b -> c) -> LogicC m a -> LogicC m b -> LogicC m c
<* :: LogicC m a -> LogicC m b -> LogicC m a
$c<* :: forall (m :: * -> *) a b. LogicC m a -> LogicC m b -> LogicC m a
*> :: LogicC m a -> LogicC m b -> LogicC m b
$c*> :: forall (m :: * -> *) a b. LogicC m a -> LogicC m b -> LogicC m b
liftA2 :: (a -> b -> c) -> LogicC m a -> LogicC m b -> LogicC m c
$cliftA2 :: forall (m :: * -> *) a b c.
(a -> b -> c) -> LogicC m a -> LogicC m b -> LogicC m c
<*> :: LogicC m (a -> b) -> LogicC m a -> LogicC m b
$c<*> :: forall (m :: * -> *) a b.
LogicC m (a -> b) -> LogicC m a -> LogicC m b
pure :: a -> LogicC m a
$cpure :: forall (m :: * -> *) a. a -> LogicC m a
$cp1Applicative :: forall (m :: * -> *). Functor (LogicC m)
Applicative, Applicative (LogicC m)
a -> LogicC m a
Applicative (LogicC m)
-> (forall a b. LogicC m a -> (a -> LogicC m b) -> LogicC m b)
-> (forall a b. LogicC m a -> LogicC m b -> LogicC m b)
-> (forall a. a -> LogicC m a)
-> Monad (LogicC m)
LogicC m a -> (a -> LogicC m b) -> LogicC m b
LogicC m a -> LogicC m b -> LogicC m b
forall a. a -> LogicC m a
forall a b. LogicC m a -> LogicC m b -> LogicC m b
forall a b. LogicC m a -> (a -> LogicC m b) -> LogicC m b
forall (m :: * -> *). Applicative (LogicC m)
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
forall (m :: * -> *) a. a -> LogicC m a
forall (m :: * -> *) a b. LogicC m a -> LogicC m b -> LogicC m b
forall (m :: * -> *) a b.
LogicC m a -> (a -> LogicC m b) -> LogicC m b
return :: a -> LogicC m a
$creturn :: forall (m :: * -> *) a. a -> LogicC m a
>> :: LogicC m a -> LogicC m b -> LogicC m b
$c>> :: forall (m :: * -> *) a b. LogicC m a -> LogicC m b -> LogicC m b
>>= :: LogicC m a -> (a -> LogicC m b) -> LogicC m b
$c>>= :: forall (m :: * -> *) a b.
LogicC m a -> (a -> LogicC m b) -> LogicC m b
$cp1Monad :: forall (m :: * -> *). Applicative (LogicC m)
Monad
           , Monad (LogicC m)
Monad (LogicC m)
-> (forall a. String -> LogicC m a) -> MonadFail (LogicC m)
String -> LogicC m a
forall a. String -> LogicC m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (LogicC m)
forall (m :: * -> *) a. MonadFail m => String -> LogicC m a
fail :: String -> LogicC m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> LogicC m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (LogicC m)
MonadFail, Monad (LogicC m)
Monad (LogicC m)
-> (forall a. IO a -> LogicC m a) -> MonadIO (LogicC m)
IO a -> LogicC m a
forall a. IO a -> LogicC m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (LogicC m)
forall (m :: * -> *) a. MonadIO m => IO a -> LogicC m a
liftIO :: IO a -> LogicC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> LogicC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (LogicC m)
MonadIO, MonadBase b
           , Monad (LogicC m)
e -> LogicC m a
Monad (LogicC m)
-> (forall e a. Exception e => e -> LogicC m a)
-> MonadThrow (LogicC m)
forall e a. Exception e => e -> LogicC m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (LogicC m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> LogicC m a
throwM :: e -> LogicC m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> LogicC m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (LogicC m)
MonadThrow, MonadThrow (LogicC m)
MonadThrow (LogicC m)
-> (forall e a.
    Exception e =>
    LogicC m a -> (e -> LogicC m a) -> LogicC m a)
-> MonadCatch (LogicC m)
LogicC m a -> (e -> LogicC m a) -> LogicC m a
forall e a.
Exception e =>
LogicC m a -> (e -> LogicC m a) -> LogicC m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (LogicC m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
LogicC m a -> (e -> LogicC m a) -> LogicC m a
catch :: LogicC m a -> (e -> LogicC m a) -> LogicC m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
LogicC m a -> (e -> LogicC m a) -> LogicC m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (LogicC m)
MonadCatch
           )
  deriving m a -> LogicC m a
(forall (m :: * -> *) a. Monad m => m a -> LogicC m a)
-> MonadTrans LogicC
forall (m :: * -> *) a. Monad m => m a -> LogicC m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> LogicC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> LogicC m a
MonadTrans


instance ( Carrier m
         , Threads L.ListT (Prims m)
         ) => Carrier (LogicC m) where
  type Derivs (LogicC m) = Split ': Cull ': Cut ': NonDet ': Derivs m
  type Prims  (LogicC m) = Split ': Regional CullOrCall ': Prims m

  algPrims :: Algebra' (Prims (LogicC m)) (LogicC m) a
algPrims = Algebra' (Regional CullOrCall : Prims m) (LogicC m) a
-> (Split (LogicC m) a -> LogicC m a)
-> Algebra' (Split : Regional CullOrCall : Prims m) (LogicC m) a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (Algebra' (Regional CullOrCall : Prims m) (CullCutC m) a
-> Algebra' (Regional CullOrCall : Prims m) (LogicC m) a
coerce (forall a.
Carrier (CullCutC m) =>
Algebra' (Prims (CullCutC m)) (CullCutC m) a
forall (m :: * -> *) a. Carrier m => Algebra' (Prims m) m a
algPrims @(CullCutC m))) ((Split (LogicC m) a -> LogicC m a)
 -> Algebra' (Split : Regional CullOrCall : Prims m) (LogicC m) a)
-> (Split (LogicC m) a -> LogicC m a)
-> Algebra' (Split : Regional CullOrCall : Prims m) (LogicC m) a
forall a b. (a -> b) -> a -> b
$ \case
    Split Maybe (a, LogicC m a) -> a
cn (m :: LogicC m a) -> (Maybe (a, LogicC m a) -> a)
-> LogicC m (Maybe (a, LogicC m a)) -> LogicC m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe (a, LogicC m a) -> a
cn ((ListT m a -> ListT m (Maybe (a, ListT m a)))
-> LogicC m a -> LogicC m (Maybe (a, LogicC m a))
coerce (Monad m => ListT m a -> ListT m (Maybe (a, ListT m a))
forall (m :: * -> *) a.
Monad m =>
ListT m a -> ListT m (Maybe (a, ListT m a))
L.split @m @a) LogicC m a
m)
  {-# INLINE algPrims #-}

  reformulate :: Reformulation'
  (Derivs (LogicC m)) (Prims (LogicC m)) (LogicC m) z a
reformulate = Reformulation'
  (Cull : Cut : NonDet : Derivs m)
  (Regional CullOrCall : Prims m)
  (LogicC m)
  z
  a
-> Reformulation'
     (Split : Cull : Cut : NonDet : Derivs m)
     (Split : Regional CullOrCall : Prims m)
     (LogicC m)
     z
     a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (p :: [(* -> *) -> * -> *]) (m :: * -> *) (z :: * -> *) a.
Monad z =>
Reformulation' r p m z a -> Reformulation' (e : r) (e : p) m z a
addPrim (Reformulation'
   (Cull : Cut : NonDet : Derivs m)
   (Regional CullOrCall : Prims m)
   (LogicC m)
   z
   a
 -> Reformulation'
      (Split : Cull : Cut : NonDet : Derivs m)
      (Split : Regional CullOrCall : Prims m)
      (LogicC m)
      z
      a)
-> Reformulation'
     (Cull : Cut : NonDet : Derivs m)
     (Regional CullOrCall : Prims m)
     (LogicC m)
     z
     a
-> Reformulation'
     (Split : Cull : Cut : NonDet : Derivs m)
     (Split : Regional CullOrCall : Prims m)
     (LogicC m)
     z
     a
forall a b. (a -> b) -> a -> b
$ Reformulation'
  (Cull : Cut : NonDet : Derivs m)
  (Regional CullOrCall : Prims m)
  (CullCutC m)
  z
  a
-> Reformulation'
     (Cull : Cut : NonDet : Derivs m)
     (Regional CullOrCall : Prims m)
     (LogicC m)
     z
     a
forall (m :: * -> *) (n :: * -> *) (r :: [(* -> *) -> * -> *])
       (p :: [(* -> *) -> * -> *]) (z :: * -> *) a.
Coercible m n =>
Reformulation' r p m z a -> Reformulation' r p n z a
coerceReform (Reformulation'
   (Cull : Cut : NonDet : Derivs m)
   (Regional CullOrCall : Prims m)
   (CullCutC m)
   z
   a
 -> Reformulation'
      (Cull : Cut : NonDet : Derivs m)
      (Regional CullOrCall : Prims m)
      (LogicC m)
      z
      a)
-> Reformulation'
     (Cull : Cut : NonDet : Derivs m)
     (Regional CullOrCall : Prims m)
     (CullCutC m)
     z
     a
-> Reformulation'
     (Cull : Cut : NonDet : Derivs m)
     (Regional CullOrCall : Prims m)
     (LogicC m)
     z
     a
forall a b. (a -> b) -> a -> b
$ forall (z :: * -> *) a.
(Carrier (CullCutC m), Monad z) =>
Reformulation'
  (Derivs (CullCutC m)) (Prims (CullCutC m)) (CullCutC m) z a
forall (m :: * -> *) (z :: * -> *) a.
(Carrier m, Monad z) =>
Reformulation' (Derivs m) (Prims m) m z a
reformulate @(CullCutC m)
  {-# INLINE reformulate #-}

data CullOrCall
  = DoCull
  | DoCall

newtype CullCutC m a = CullCutC { CullCutC m a -> ListT m a
unCullCutC :: L.ListT m a }
  deriving ( a -> CullCutC m b -> CullCutC m a
(a -> b) -> CullCutC m a -> CullCutC m b
(forall a b. (a -> b) -> CullCutC m a -> CullCutC m b)
-> (forall a b. a -> CullCutC m b -> CullCutC m a)
-> Functor (CullCutC m)
forall a b. a -> CullCutC m b -> CullCutC m a
forall a b. (a -> b) -> CullCutC m a -> CullCutC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (m :: * -> *) a b. a -> CullCutC m b -> CullCutC m a
forall (m :: * -> *) a b. (a -> b) -> CullCutC m a -> CullCutC m b
<$ :: a -> CullCutC m b -> CullCutC m a
$c<$ :: forall (m :: * -> *) a b. a -> CullCutC m b -> CullCutC m a
fmap :: (a -> b) -> CullCutC m a -> CullCutC m b
$cfmap :: forall (m :: * -> *) a b. (a -> b) -> CullCutC m a -> CullCutC m b
Functor, Functor (CullCutC m)
a -> CullCutC m a
Functor (CullCutC m)
-> (forall a. a -> CullCutC m a)
-> (forall a b.
    CullCutC m (a -> b) -> CullCutC m a -> CullCutC m b)
-> (forall a b c.
    (a -> b -> c) -> CullCutC m a -> CullCutC m b -> CullCutC m c)
-> (forall a b. CullCutC m a -> CullCutC m b -> CullCutC m b)
-> (forall a b. CullCutC m a -> CullCutC m b -> CullCutC m a)
-> Applicative (CullCutC m)
CullCutC m a -> CullCutC m b -> CullCutC m b
CullCutC m a -> CullCutC m b -> CullCutC m a
CullCutC m (a -> b) -> CullCutC m a -> CullCutC m b
(a -> b -> c) -> CullCutC m a -> CullCutC m b -> CullCutC m c
forall a. a -> CullCutC m a
forall a b. CullCutC m a -> CullCutC m b -> CullCutC m a
forall a b. CullCutC m a -> CullCutC m b -> CullCutC m b
forall a b. CullCutC m (a -> b) -> CullCutC m a -> CullCutC m b
forall a b c.
(a -> b -> c) -> CullCutC m a -> CullCutC m b -> CullCutC m c
forall (m :: * -> *). Functor (CullCutC m)
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *) a. a -> CullCutC m a
forall (m :: * -> *) a b.
CullCutC m a -> CullCutC m b -> CullCutC m a
forall (m :: * -> *) a b.
CullCutC m a -> CullCutC m b -> CullCutC m b
forall (m :: * -> *) a b.
CullCutC m (a -> b) -> CullCutC m a -> CullCutC m b
forall (m :: * -> *) a b c.
(a -> b -> c) -> CullCutC m a -> CullCutC m b -> CullCutC m c
<* :: CullCutC m a -> CullCutC m b -> CullCutC m a
$c<* :: forall (m :: * -> *) a b.
CullCutC m a -> CullCutC m b -> CullCutC m a
*> :: CullCutC m a -> CullCutC m b -> CullCutC m b
$c*> :: forall (m :: * -> *) a b.
CullCutC m a -> CullCutC m b -> CullCutC m b
liftA2 :: (a -> b -> c) -> CullCutC m a -> CullCutC m b -> CullCutC m c
$cliftA2 :: forall (m :: * -> *) a b c.
(a -> b -> c) -> CullCutC m a -> CullCutC m b -> CullCutC m c
<*> :: CullCutC m (a -> b) -> CullCutC m a -> CullCutC m b
$c<*> :: forall (m :: * -> *) a b.
CullCutC m (a -> b) -> CullCutC m a -> CullCutC m b
pure :: a -> CullCutC m a
$cpure :: forall (m :: * -> *) a. a -> CullCutC m a
$cp1Applicative :: forall (m :: * -> *). Functor (CullCutC m)
Applicative, Applicative (CullCutC m)
a -> CullCutC m a
Applicative (CullCutC m)
-> (forall a b.
    CullCutC m a -> (a -> CullCutC m b) -> CullCutC m b)
-> (forall a b. CullCutC m a -> CullCutC m b -> CullCutC m b)
-> (forall a. a -> CullCutC m a)
-> Monad (CullCutC m)
CullCutC m a -> (a -> CullCutC m b) -> CullCutC m b
CullCutC m a -> CullCutC m b -> CullCutC m b
forall a. a -> CullCutC m a
forall a b. CullCutC m a -> CullCutC m b -> CullCutC m b
forall a b. CullCutC m a -> (a -> CullCutC m b) -> CullCutC m b
forall (m :: * -> *). Applicative (CullCutC m)
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
forall (m :: * -> *) a. a -> CullCutC m a
forall (m :: * -> *) a b.
CullCutC m a -> CullCutC m b -> CullCutC m b
forall (m :: * -> *) a b.
CullCutC m a -> (a -> CullCutC m b) -> CullCutC m b
return :: a -> CullCutC m a
$creturn :: forall (m :: * -> *) a. a -> CullCutC m a
>> :: CullCutC m a -> CullCutC m b -> CullCutC m b
$c>> :: forall (m :: * -> *) a b.
CullCutC m a -> CullCutC m b -> CullCutC m b
>>= :: CullCutC m a -> (a -> CullCutC m b) -> CullCutC m b
$c>>= :: forall (m :: * -> *) a b.
CullCutC m a -> (a -> CullCutC m b) -> CullCutC m b
$cp1Monad :: forall (m :: * -> *). Applicative (CullCutC m)
Monad
           , Monad (CullCutC m)
Monad (CullCutC m)
-> (forall a. String -> CullCutC m a) -> MonadFail (CullCutC m)
String -> CullCutC m a
forall a. String -> CullCutC m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (CullCutC m)
forall (m :: * -> *) a. MonadFail m => String -> CullCutC m a
fail :: String -> CullCutC m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> CullCutC m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (CullCutC m)
MonadFail, Monad (CullCutC m)
Monad (CullCutC m)
-> (forall a. IO a -> CullCutC m a) -> MonadIO (CullCutC m)
IO a -> CullCutC m a
forall a. IO a -> CullCutC m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (CullCutC m)
forall (m :: * -> *) a. MonadIO m => IO a -> CullCutC m a
liftIO :: IO a -> CullCutC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> CullCutC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (CullCutC m)
MonadIO, MonadBase b
           , Monad (CullCutC m)
e -> CullCutC m a
Monad (CullCutC m)
-> (forall e a. Exception e => e -> CullCutC m a)
-> MonadThrow (CullCutC m)
forall e a. Exception e => e -> CullCutC m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (CullCutC m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> CullCutC m a
throwM :: e -> CullCutC m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> CullCutC m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (CullCutC m)
MonadThrow, MonadThrow (CullCutC m)
MonadThrow (CullCutC m)
-> (forall e a.
    Exception e =>
    CullCutC m a -> (e -> CullCutC m a) -> CullCutC m a)
-> MonadCatch (CullCutC m)
CullCutC m a -> (e -> CullCutC m a) -> CullCutC m a
forall e a.
Exception e =>
CullCutC m a -> (e -> CullCutC m a) -> CullCutC m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (CullCutC m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
CullCutC m a -> (e -> CullCutC m a) -> CullCutC m a
catch :: CullCutC m a -> (e -> CullCutC m a) -> CullCutC m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
CullCutC m a -> (e -> CullCutC m a) -> CullCutC m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (CullCutC m)
MonadCatch
           )
  deriving m a -> CullCutC m a
(forall (m :: * -> *) a. Monad m => m a -> CullCutC m a)
-> MonadTrans CullCutC
forall (m :: * -> *) a. Monad m => m a -> CullCutC m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> CullCutC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> CullCutC m a
MonadTrans

instance ( Carrier m
         , Threads L.ListT (Prims m)
         ) => Carrier (CullCutC m) where
  type Derivs (CullCutC m) = Cull ': Cut ': NonDet ': Derivs m
  type Prims  (CullCutC m) = Regional CullOrCall ': Prims m

  algPrims :: Algebra' (Prims (CullCutC m)) (CullCutC m) a
algPrims =
    Algebra' (Prims m) (CullCutC m) a
-> (Regional CullOrCall (CullCutC m) a -> CullCutC m a)
-> Algebra' (Regional CullOrCall : Prims m) (CullCutC m) a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (
      Algebra' (Prims m) (NonDetC m) a
-> Algebra' (Prims m) (CullCutC m) a
coerce (forall a.
Carrier (NonDetC m) =>
Algebra' (Prims (NonDetC m)) (NonDetC m) a
forall (m :: * -> *) a. Carrier m => Algebra' (Prims m) m a
algPrims @(NonDetC m))
    ) ((Regional CullOrCall (CullCutC m) a -> CullCutC m a)
 -> Algebra' (Regional CullOrCall : Prims m) (CullCutC m) a)
-> (Regional CullOrCall (CullCutC m) a -> CullCutC m a)
-> Algebra' (Regional CullOrCall : Prims m) (CullCutC m) a
forall a b. (a -> b) -> a -> b
$ \case
        Regionally CullOrCall
DoCull CullCutC m a
m -> (ListT m a -> ListT m a) -> CullCutC m a -> CullCutC m a
forall k1 k2 (m :: k1 -> *) (z :: k1 -> *) (n :: k2 -> *)
       (y :: k2 -> *) (a :: k1) (b :: k2).
(Coercible m z, Coercible n y) =>
(m a -> n b) -> z a -> y b
coerceTrans (forall a. ListT m a -> ListT m a
forall (m :: * -> *) a. ListT m a -> ListT m a
L.cull @m) CullCutC m a
m
        Regionally CullOrCall
DoCall CullCutC m a
m -> (ListT m a -> ListT m a) -> CullCutC m a -> CullCutC m a
forall k1 k2 (m :: k1 -> *) (z :: k1 -> *) (n :: k2 -> *)
       (y :: k2 -> *) (a :: k1) (b :: k2).
(Coercible m z, Coercible n y) =>
(m a -> n b) -> z a -> y b
coerceTrans (forall a. ListT m a -> ListT m a
forall (m :: * -> *) a. ListT m a -> ListT m a
L.call @m) CullCutC m a
m
  {-# INLINEABLE algPrims #-}

  reformulate :: Reformulation'
  (Derivs (CullCutC m)) (Prims (CullCutC m)) (CullCutC m) z a
reformulate forall x. CullCutC m x -> z x
n Algebra (Prims (CullCutC m)) z
alg =
    Algebra' (Cut : NonDet : Derivs m) z a
-> (Cull z a -> z a)
-> Algebra' (Cull : Cut : NonDet : Derivs m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (
    Algebra' (NonDet : Derivs m) z a
-> (Cut z a -> z a) -> Algebra' (Cut : NonDet : Derivs m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (
      Reformulation' (NonDet : Derivs m) (Prims m) (NonDetC m) z a
-> Reformulation' (NonDet : Derivs m) (Prims m) (CullCutC m) z a
forall (m :: * -> *) (n :: * -> *) (r :: [(* -> *) -> * -> *])
       (p :: [(* -> *) -> * -> *]) (z :: * -> *) a.
Coercible m n =>
Reformulation' r p m z a -> Reformulation' r p n z a
coerceReform (forall (z :: * -> *) a.
(Carrier (NonDetC m), Monad z) =>
Reformulation'
  (Derivs (NonDetC m)) (Prims (NonDetC m)) (NonDetC m) z a
forall (m :: * -> *) (z :: * -> *) a.
(Carrier m, Monad z) =>
Reformulation' (Derivs m) (Prims m) m z a
reformulate @(NonDetC m)) forall x. CullCutC m x -> z x
n (Algebra' (Regional CullOrCall : Prims m) z x
-> Algebra' (Prims m) z x
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
Algebra' (e : r) m a -> Algebra' r m a
weakenAlg Algebra' (Regional CullOrCall : Prims m) z x
Algebra (Prims (CullCutC m)) z
alg)
    ) ((Cut z a -> z a) -> Algebra' (Cut : NonDet : Derivs m) z a)
-> (Cut z a -> z a) -> Algebra' (Cut : NonDet : Derivs m) z a
forall a b. (a -> b) -> a -> b
$ \case
      Cut z a
Cutfail -> CullCutC m a -> z a
forall x. CullCutC m x -> z x
n (ListT m a -> CullCutC m a
forall (m :: * -> *) a. ListT m a -> CullCutC m a
CullCutC ListT m a
forall (m :: * -> *) a. ListT m a
L.cutfail)
      Call z a
m  -> (Union (Regional CullOrCall : Prims m) z a -> z a
Algebra (Prims (CullCutC m)) z
alg (Union (Regional CullOrCall : Prims m) z a -> z a)
-> (Regional CullOrCall z a
    -> Union (Regional CullOrCall : Prims m) z a)
-> Regional CullOrCall z a
-> z a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Regional CullOrCall z a
-> Union (Regional CullOrCall : Prims m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
Member e r =>
e m a -> Union r m a
inj) (Regional CullOrCall z a -> z a) -> Regional CullOrCall z a -> z a
forall a b. (a -> b) -> a -> b
$ CullOrCall -> z a -> Regional CullOrCall z a
forall s (m :: * -> *) a. s -> m a -> Regional s m a
Regionally CullOrCall
DoCall z a
m
    ) ((Cull z a -> z a)
 -> Algebra' (Cull : Cut : NonDet : Derivs m) z a)
-> (Cull z a -> z a)
-> Algebra' (Cull : Cut : NonDet : Derivs m) z a
forall a b. (a -> b) -> a -> b
$ \case
      Cull z a
m  -> (Union (Regional CullOrCall : Prims m) z a -> z a
Algebra (Prims (CullCutC m)) z
alg (Union (Regional CullOrCall : Prims m) z a -> z a)
-> (Regional CullOrCall z a
    -> Union (Regional CullOrCall : Prims m) z a)
-> Regional CullOrCall z a
-> z a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Regional CullOrCall z a
-> Union (Regional CullOrCall : Prims m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
Member e r =>
e m a -> Union r m a
inj) (Regional CullOrCall z a -> z a) -> Regional CullOrCall z a -> z a
forall a b. (a -> b) -> a -> b
$ CullOrCall -> z a -> Regional CullOrCall z a
forall s (m :: * -> *) a. s -> m a -> Regional s m a
Regionally CullOrCall
DoCull z a
m
  {-# INLINEABLE reformulate #-}

newtype NonDetC m a = NonDetC { NonDetC m a -> ListT m a
unNonDetC :: L.ListT m a }
  deriving ( a -> NonDetC m b -> NonDetC m a
(a -> b) -> NonDetC m a -> NonDetC m b
(forall a b. (a -> b) -> NonDetC m a -> NonDetC m b)
-> (forall a b. a -> NonDetC m b -> NonDetC m a)
-> Functor (NonDetC m)
forall a b. a -> NonDetC m b -> NonDetC m a
forall a b. (a -> b) -> NonDetC m a -> NonDetC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (m :: * -> *) a b. a -> NonDetC m b -> NonDetC m a
forall (m :: * -> *) a b. (a -> b) -> NonDetC m a -> NonDetC m b
<$ :: a -> NonDetC m b -> NonDetC m a
$c<$ :: forall (m :: * -> *) a b. a -> NonDetC m b -> NonDetC m a
fmap :: (a -> b) -> NonDetC m a -> NonDetC m b
$cfmap :: forall (m :: * -> *) a b. (a -> b) -> NonDetC m a -> NonDetC m b
Functor, Functor (NonDetC m)
a -> NonDetC m a
Functor (NonDetC m)
-> (forall a. a -> NonDetC m a)
-> (forall a b. NonDetC m (a -> b) -> NonDetC m a -> NonDetC m b)
-> (forall a b c.
    (a -> b -> c) -> NonDetC m a -> NonDetC m b -> NonDetC m c)
-> (forall a b. NonDetC m a -> NonDetC m b -> NonDetC m b)
-> (forall a b. NonDetC m a -> NonDetC m b -> NonDetC m a)
-> Applicative (NonDetC m)
NonDetC m a -> NonDetC m b -> NonDetC m b
NonDetC m a -> NonDetC m b -> NonDetC m a
NonDetC m (a -> b) -> NonDetC m a -> NonDetC m b
(a -> b -> c) -> NonDetC m a -> NonDetC m b -> NonDetC m c
forall a. a -> NonDetC m a
forall a b. NonDetC m a -> NonDetC m b -> NonDetC m a
forall a b. NonDetC m a -> NonDetC m b -> NonDetC m b
forall a b. NonDetC m (a -> b) -> NonDetC m a -> NonDetC m b
forall a b c.
(a -> b -> c) -> NonDetC m a -> NonDetC m b -> NonDetC m c
forall (m :: * -> *). Functor (NonDetC m)
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *) a. a -> NonDetC m a
forall (m :: * -> *) a b. NonDetC m a -> NonDetC m b -> NonDetC m a
forall (m :: * -> *) a b. NonDetC m a -> NonDetC m b -> NonDetC m b
forall (m :: * -> *) a b.
NonDetC m (a -> b) -> NonDetC m a -> NonDetC m b
forall (m :: * -> *) a b c.
(a -> b -> c) -> NonDetC m a -> NonDetC m b -> NonDetC m c
<* :: NonDetC m a -> NonDetC m b -> NonDetC m a
$c<* :: forall (m :: * -> *) a b. NonDetC m a -> NonDetC m b -> NonDetC m a
*> :: NonDetC m a -> NonDetC m b -> NonDetC m b
$c*> :: forall (m :: * -> *) a b. NonDetC m a -> NonDetC m b -> NonDetC m b
liftA2 :: (a -> b -> c) -> NonDetC m a -> NonDetC m b -> NonDetC m c
$cliftA2 :: forall (m :: * -> *) a b c.
(a -> b -> c) -> NonDetC m a -> NonDetC m b -> NonDetC m c
<*> :: NonDetC m (a -> b) -> NonDetC m a -> NonDetC m b
$c<*> :: forall (m :: * -> *) a b.
NonDetC m (a -> b) -> NonDetC m a -> NonDetC m b
pure :: a -> NonDetC m a
$cpure :: forall (m :: * -> *) a. a -> NonDetC m a
$cp1Applicative :: forall (m :: * -> *). Functor (NonDetC m)
Applicative, Applicative (NonDetC m)
a -> NonDetC m a
Applicative (NonDetC m)
-> (forall a b. NonDetC m a -> (a -> NonDetC m b) -> NonDetC m b)
-> (forall a b. NonDetC m a -> NonDetC m b -> NonDetC m b)
-> (forall a. a -> NonDetC m a)
-> Monad (NonDetC m)
NonDetC m a -> (a -> NonDetC m b) -> NonDetC m b
NonDetC m a -> NonDetC m b -> NonDetC m b
forall a. a -> NonDetC m a
forall a b. NonDetC m a -> NonDetC m b -> NonDetC m b
forall a b. NonDetC m a -> (a -> NonDetC m b) -> NonDetC m b
forall (m :: * -> *). Applicative (NonDetC m)
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
forall (m :: * -> *) a. a -> NonDetC m a
forall (m :: * -> *) a b. NonDetC m a -> NonDetC m b -> NonDetC m b
forall (m :: * -> *) a b.
NonDetC m a -> (a -> NonDetC m b) -> NonDetC m b
return :: a -> NonDetC m a
$creturn :: forall (m :: * -> *) a. a -> NonDetC m a
>> :: NonDetC m a -> NonDetC m b -> NonDetC m b
$c>> :: forall (m :: * -> *) a b. NonDetC m a -> NonDetC m b -> NonDetC m b
>>= :: NonDetC m a -> (a -> NonDetC m b) -> NonDetC m b
$c>>= :: forall (m :: * -> *) a b.
NonDetC m a -> (a -> NonDetC m b) -> NonDetC m b
$cp1Monad :: forall (m :: * -> *). Applicative (NonDetC m)
Monad
           , Monad (NonDetC m)
Monad (NonDetC m)
-> (forall a. String -> NonDetC m a) -> MonadFail (NonDetC m)
String -> NonDetC m a
forall a. String -> NonDetC m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (NonDetC m)
forall (m :: * -> *) a. MonadFail m => String -> NonDetC m a
fail :: String -> NonDetC m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> NonDetC m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (NonDetC m)
MonadFail, Monad (NonDetC m)
Monad (NonDetC m)
-> (forall a. IO a -> NonDetC m a) -> MonadIO (NonDetC m)
IO a -> NonDetC m a
forall a. IO a -> NonDetC m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (NonDetC m)
forall (m :: * -> *) a. MonadIO m => IO a -> NonDetC m a
liftIO :: IO a -> NonDetC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> NonDetC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (NonDetC m)
MonadIO, MonadBase b
           , Monad (NonDetC m)
e -> NonDetC m a
Monad (NonDetC m)
-> (forall e a. Exception e => e -> NonDetC m a)
-> MonadThrow (NonDetC m)
forall e a. Exception e => e -> NonDetC m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (NonDetC m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> NonDetC m a
throwM :: e -> NonDetC m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> NonDetC m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (NonDetC m)
MonadThrow, MonadThrow (NonDetC m)
MonadThrow (NonDetC m)
-> (forall e a.
    Exception e =>
    NonDetC m a -> (e -> NonDetC m a) -> NonDetC m a)
-> MonadCatch (NonDetC m)
NonDetC m a -> (e -> NonDetC m a) -> NonDetC m a
forall e a.
Exception e =>
NonDetC m a -> (e -> NonDetC m a) -> NonDetC m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (NonDetC m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
NonDetC m a -> (e -> NonDetC m a) -> NonDetC m a
catch :: NonDetC m a -> (e -> NonDetC m a) -> NonDetC m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
NonDetC m a -> (e -> NonDetC m a) -> NonDetC m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (NonDetC m)
MonadCatch
           )
  deriving m a -> NonDetC m a
(forall (m :: * -> *) a. Monad m => m a -> NonDetC m a)
-> MonadTrans NonDetC
forall (m :: * -> *) a. Monad m => m a -> NonDetC m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> NonDetC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> NonDetC m a
MonadTrans

instance ( Carrier m
         , Threads L.ListT (Prims m)
         ) => Carrier (NonDetC m) where
  type Derivs (NonDetC m) = NonDet ': Derivs m
  type Prims  (NonDetC m) = Prims m

  algPrims :: Algebra' (Prims (NonDetC m)) (NonDetC m) a
algPrims = (Union (Prims m) (ListT m) a -> ListT m a)
-> Algebra' (Prims m) (NonDetC m) a
coerce (Algebra (Prims m) m -> Algebra (Prims m) (ListT m)
forall (t :: (* -> *) -> * -> *) (p :: [(* -> *) -> * -> *])
       (m :: * -> *).
(Threads t p, Monad m) =>
Algebra p m -> Algebra p (t m)
thread @L.ListT (Carrier m => Algebra (Prims m) m
forall (m :: * -> *) a. Carrier m => Algebra' (Prims m) m a
algPrims @m))
  {-# INLINEABLE algPrims #-}

  reformulate :: Reformulation'
  (Derivs (NonDetC m)) (Prims (NonDetC m)) (NonDetC m) z a
reformulate forall x. NonDetC m x -> z x
n Algebra (Prims (NonDetC m)) z
alg =
    Algebra' (Derivs m) z a
-> (NonDet z a -> z a) -> Algebra' (NonDet : Derivs m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg
      (Reformulation' (Derivs m) (Prims m) m z a
-> Reformulation' (Derivs m) (Prims m) (NonDetC m) z a
forall (t :: (* -> *) -> * -> *) (m :: * -> *)
       (r :: [(* -> *) -> * -> *]) (p :: [(* -> *) -> * -> *])
       (z :: * -> *) a.
(MonadTrans t, Monad m) =>
Reformulation' r p m z a -> Reformulation' r p (t m) z a
liftReform Reformulation' (Derivs m) (Prims m) m z a
forall (m :: * -> *) (z :: * -> *) a.
(Carrier m, Monad z) =>
Reformulation' (Derivs m) (Prims m) m z a
reformulate forall x. NonDetC m x -> z x
n forall x. Union (Prims m) z x -> z x
Algebra (Prims (NonDetC m)) z
alg)
      ((NonDet z a -> z a) -> Algebra' (NonDet : Derivs m) z a)
-> (NonDet z a -> z a) -> Algebra' (NonDet : Derivs m) z a
forall a b. (a -> b) -> a -> b
$ \case
        FromList [a]
l -> NonDetC m a -> z a
forall x. NonDetC m x -> z x
n (NonDetC m a -> z a) -> NonDetC m a -> z a
forall a b. (a -> b) -> a -> b
$ ListT m a -> NonDetC m a
forall (m :: * -> *) a. ListT m a -> NonDetC m a
NonDetC (ListT m a -> NonDetC m a) -> ListT m a -> NonDetC m a
forall a b. (a -> b) -> a -> b
$ (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
L.ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
_ -> (a -> m r -> m r) -> m r -> [a] -> m r
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> m r -> m r
c m r
b [a]
l
  {-# INLINEABLE reformulate #-}


-- | Runs a 'NonDet' effect.
--
-- Unlike 'runLogic' and 'runCullCut', this doesn't provide any means of interacting
-- with created branches through 'Split', 'Cull' or 'Cut'.
--
-- However, it also doesn't impose any primitive effects, meaning 'runNonDet' doesn't
-- restrict what interpreters are run before it.
--
-- @'Derivs' ('NonDetC' m) = 'NonDet' ': 'Derivs' m@
--
-- @'Prims'  ('NonDetC' m) = 'Prims' m@
runNonDet :: forall f m a p
           . ( Alternative f
             , Carrier m
             , Threaders '[NonDetThreads] m p
             )
          => NonDetC m a
          -> m (f a)
runNonDet :: NonDetC m a -> m (f a)
runNonDet = ListT m a -> m (f a)
forall (f :: * -> *) (m :: * -> *) a.
(Alternative f, Monad m) =>
ListT m a -> m (f a)
L.runListT (ListT m a -> m (f a))
-> (NonDetC m a -> ListT m a) -> NonDetC m a -> m (f a)
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# NonDetC m a -> ListT m a
forall (m :: * -> *) a. NonDetC m a -> ListT m a
unNonDetC
{-# INLINE runNonDet #-}


-- | Runs a 'NonDet' effect, but stop once the first valid result is found.
--
-- This is like 'runNonDet' with the 'Alternative' specialized to 'Maybe',
-- but once a valid result is found, it won't run all other branches.
--
-- This is the equivalent of
-- @'runCullCut' \@Maybe . 'Control.Effect.NonDet.cull'@
-- or @'runLogic' \@Maybe . 'Control.Effect.NonDet.cull'@, but doesn't impose
-- any primitive effects, meaning 'runNonDet1' doesn't restrict what interpreters
-- are run before it.
--
-- @'Derivs' ('NonDetC' m) = 'NonDet' ': 'Derivs' m@
--
-- @'Prims'  ('NonDetC' m) = 'Prims' m@
runNonDet1 :: forall m a p
            . ( Carrier m
              , Threaders '[NonDetThreads] m p
              )
           => NonDetC m a
           -> m (Maybe a)
runNonDet1 :: NonDetC m a -> m (Maybe a)
runNonDet1 NonDetC m a
m =
  ListT m a
-> (a -> m (Maybe a) -> m (Maybe a))
-> m (Maybe a)
-> m (Maybe a)
-> m (Maybe a)
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
L.unListT (NonDetC m a -> ListT m a
forall (m :: * -> *) a. NonDetC m a -> ListT m a
unNonDetC NonDetC m a
m)
            (\a
a m (Maybe a)
_ -> Maybe a -> m (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Maybe a
forall a. a -> Maybe a
Just a
a))
            (Maybe a -> m (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing)
            (Maybe a -> m (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing)
{-# INLINE runNonDet1 #-}

-- | Runs connected 'NonDet', 'Cull', and 'Cut' effects.
--
-- Unlike 'runLogic', this doesn't provide the full power of 'Split'.
-- This allows for a larger variety of interpreters to be run before
-- 'runCullCut' compared to 'runLogic', since 'Split' is significantly harder to
-- thread compared to 'Cull' and 'Cut'.
--
-- @'Derivs' ('CullCutC' m) = 'Cull' ': 'Cut' ': 'NonDet' ': 'Derivs' m@
--
-- @'Prims'  ('CullCutC' m) = 'Regional' CullOrCall ': 'Prims' m@
runCullCut :: forall f m a p
            . ( Alternative f
              , Carrier m
              , Threaders '[NonDetThreads] m p
              )
           => CullCutC m a
           -> m (f a)
runCullCut :: CullCutC m a -> m (f a)
runCullCut = ListT m a -> m (f a)
forall (f :: * -> *) (m :: * -> *) a.
(Alternative f, Monad m) =>
ListT m a -> m (f a)
L.runListT (ListT m a -> m (f a))
-> (CullCutC m a -> ListT m a) -> CullCutC m a -> m (f a)
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# CullCutC m a -> ListT m a
forall (m :: * -> *) a. CullCutC m a -> ListT m a
unCullCutC

-- | Runs connected 'NonDet', 'Cull', 'Cut', and 'Split' effects
-- -- i.e. 'Control.Effect.NonDet.Logic'.
--
-- @'Derivs' ('LogicC' m) = 'Split' ': 'Cull' ': 'Cut' ': 'NonDet' ': 'Derivs' m@
--
-- @'Prims'  ('LogicC' m) = 'Split' ': 'Regional' CullOrCall ': 'Prims' m@
--
-- 'Split' is a very restrictive primitive effect. Most notably,
-- interpreters for effects with failure -- such as
-- 'Control.Effect.Error.runError' -- can't be used before 'runLogic'.
-- If you want to use such interpreters before 'runLogic',
-- consider using 'runCullCut' or 'runNonDet' instead.
runLogic :: forall f m a p
          . ( Alternative f
            , Carrier m
            , Threaders '[NonDetThreads] m p
            )
         => LogicC m a
         -> m (f a)
runLogic :: LogicC m a -> m (f a)
runLogic = ListT m a -> m (f a)
forall (f :: * -> *) (m :: * -> *) a.
(Alternative f, Monad m) =>
ListT m a -> m (f a)
L.runListT (ListT m a -> m (f a))
-> (LogicC m a -> ListT m a) -> LogicC m a -> m (f a)
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# LogicC m a -> ListT m a
forall (m :: * -> *) a. LogicC m a -> ListT m a
unLogicC