1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 05:11:44 +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,18 +111,14 @@ while :: Member (While value) effects
while (Evaluator cond) (Evaluator body) = send (While cond body)
-- | 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
doWhile body cond = undefined
doWhile body cond = body *> while cond body
-- | C-style for loops.
forLoop :: ( AbstractValue address value effects
, Member (Boolean value) effects
, Member (While value) effects
, Member (Env address) effects
)
forLoop :: (Member (While value) effects, Member (Env address) effects)
=> Evaluator address value effects value -- ^ Initial statement
-> Evaluator address value effects value -- ^ Condition
-> Evaluator address value effects value -- ^ Increment/stepper
@ -131,24 +127,6 @@ forLoop :: ( AbstractValue address value effects
forLoop initial cond step body =
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
While :: m value -> m value -> While value m value