From 8193df2c9ac3fbea9250f977752882401da3a038 Mon Sep 17 00:00:00 2001 From: Morgan Thomas Date: Thu, 10 Jun 2021 20:54:31 -0400 Subject: [PATCH 1/2] add indefinitely combinator for repeating a continuation without a stopping condition --- core/Shpadoinkle/Continuation.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/Shpadoinkle/Continuation.hs b/core/Shpadoinkle/Continuation.hs index df430cd9..fc4e90fb 100644 --- a/core/Shpadoinkle/Continuation.hs +++ b/core/Shpadoinkle/Continuation.hs @@ -26,6 +26,8 @@ module Shpadoinkle.Continuation ( , hoist -- * Forgetting , voidC', voidC, forgetC + -- * Repetition + , indefinitely -- * Lifts , liftC', liftCMay', liftC, liftCMay -- * Utilities @@ -238,6 +240,21 @@ forgetC :: Continuous f => f m a -> f m b forgetC = mapC (const done) +-- | Repeat a Continuation "forever" (until the program halts). +indefinitely :: Applicative m => Continuation m a -> Continuation m a +indefinitely c = c `before` (indefinitely c) + + +-- | Run a Continuation whenever the state obtains a value satisfying a predicate. +--whenever :: Applicative m => (a -> Bool) -> Continuation m a -> Continuation m a +--whenever p c = indefinitely . kleisli $ \a -> pure $ if p a then c else done + + +-- | Repeat a Continuation whenever the state obtains a value satifying a predicate until a stopping condition is met. +--wheneverWhile :: Applicative m => (a -> Bool) -> (a -> Bool) -> Continuation m a -> Continuation m a +--wheneverWhile + + --- | Change the type of a Continuation by applying it to the left coordinate of a tuple. {-# SPECIALIZE leftC' :: Continuation JSM a -> Continuation JSM (a,b) #-} leftC' :: Functor m => Continuation m a -> Continuation m (a,b) -- GitLab From 2f24dead9ff202cb7c8c9e30f79cc93d4cc838ad Mon Sep 17 00:00:00 2001 From: Morgan Thomas Date: Thu, 10 Jun 2021 20:59:08 -0400 Subject: [PATCH 2/2] remove commented code --- core/Shpadoinkle/Continuation.hs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/Shpadoinkle/Continuation.hs b/core/Shpadoinkle/Continuation.hs index fc4e90fb..a2de0888 100644 --- a/core/Shpadoinkle/Continuation.hs +++ b/core/Shpadoinkle/Continuation.hs @@ -245,16 +245,6 @@ indefinitely :: Applicative m => Continuation m a -> Continuation m a indefinitely c = c `before` (indefinitely c) --- | Run a Continuation whenever the state obtains a value satisfying a predicate. ---whenever :: Applicative m => (a -> Bool) -> Continuation m a -> Continuation m a ---whenever p c = indefinitely . kleisli $ \a -> pure $ if p a then c else done - - --- | Repeat a Continuation whenever the state obtains a value satifying a predicate until a stopping condition is met. ---wheneverWhile :: Applicative m => (a -> Bool) -> (a -> Bool) -> Continuation m a -> Continuation m a ---wheneverWhile - - --- | Change the type of a Continuation by applying it to the left coordinate of a tuple. {-# SPECIALIZE leftC' :: Continuation JSM a -> Continuation JSM (a,b) #-} leftC' :: Functor m => Continuation m a -> Continuation m (a,b) -- GitLab