loopbreak nondet

This commit is contained in:
Sandy Maguire 2019-03-21 01:24:20 -04:00
parent df7c9be46d
commit 9dd70fa096

View File

@ -1,4 +1,5 @@
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
module Polysemy.NonDet module Polysemy.NonDet
( NonDet (..) ( NonDet (..)
@ -47,12 +48,14 @@ instance Monad (NonDetC m) where
{-# INLINE (>>=) #-} {-# INLINE (>>=) #-}
runNonDet :: Alternative f => Semantic (NonDet ': r) a -> Semantic r (f a) inlineRecursiveCalls [d|
runNonDet (Semantic m) = Semantic $ \k -> runNonDetC $ m $ \u -> runNonDet :: Alternative f => Semantic (NonDet ': r) a -> Semantic r (f a)
case decomp u of runNonDet (Semantic m) = Semantic $ \k -> runNonDetC $ m $ \u ->
Left x -> NonDetC $ \cons nil -> do case decomp u of
z <- k $ weave [()] (fmap concat . traverse runNonDet) x Left x -> NonDetC $ \cons nil -> do
foldr cons nil z z <- k $ weave [()] (fmap concat . traverse runNonDet) x
Right Empty -> empty foldr cons nil z
Right (Choose ek) -> pure (ek True) <|> pure (ek False) Right Empty -> empty
Right (Choose ek) -> pure (ek True) <|> pure (ek False)
|]