1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Implement doWhile in terms of the new while effect

This commit is contained in:
Timothy Clem 2018-09-20 09:42:55 -07:00
parent fdfc47e168
commit 741a3b25d6

View File

@ -111,44 +111,22 @@ while :: Member (While value) effects
while (Evaluator cond) (Evaluator body) = send (While cond body) while (Evaluator cond) (Evaluator body) = send (While cond body)
-- | Do-while loop, built on top of while. -- | Do-while loop, built on top of while.
doWhile :: (AbstractValue address value effects, Member (Boolean value) effects) doWhile :: Member (While value) effects
=> Evaluator address value effects value => Evaluator address value effects value
-> Evaluator address value effects value -> Evaluator address value effects value
-> Evaluator address value effects value -> Evaluator address value effects value
doWhile body cond = undefined doWhile body cond = body *> while cond body
-- | C-style for loops. -- | C-style for loops.
forLoop :: ( AbstractValue address value effects forLoop :: (Member (While value) effects, Member (Env address) effects)
, Member (Boolean value) effects => Evaluator address value effects value -- ^ Initial statement
, Member (While value) effects -> Evaluator address value effects value -- ^ Condition
, Member (Env address) effects -> Evaluator address value effects value -- ^ Increment/stepper
) -> Evaluator address value effects value -- ^ Body
=> Evaluator address value effects value -- ^ Initial statement -> Evaluator address value effects value
-> Evaluator address value effects value -- ^ Condition
-> Evaluator address value effects value -- ^ Increment/stepper
-> Evaluator address value effects value -- ^ Body
-> Evaluator address value effects value
forLoop initial cond step body = forLoop initial cond step body =
locally (initial *> while cond (body *> step)) locally (initial *> while cond (body *> step))
-- -- | The fundamental looping primitive, built on top of 'ifthenelse'.
-- while :: (AbstractValue address value effects, Member (Boolean value) effects)
-- => Evaluator address value effects value
-- -> Evaluator address value effects value
-- -> Evaluator address value effects value
-- while cond body = loop $ \ continue -> do
-- this <- cond
-- ifthenelse this (body *> continue) (pure unit)
--
-- -- | Do-while loop, built on top of while.
-- doWhile :: (AbstractValue address value effects, Member (Boolean value) effects)
-- => Evaluator address value effects value
-- -> Evaluator address value effects value
-- -> Evaluator address value effects value
-- doWhile body cond = loop $ \ continue -> body *> do
-- this <- cond
-- ifthenelse this continue (pure unit)
data While value m result where data While value m result where
While :: m value -> m value -> While value m value While :: m value -> m value -> While value m value