loop example

This commit is contained in:
Schell Scivally 2017-03-14 12:40:12 -07:00 committed by Peter Trško
parent 07ee1289bc
commit 7094f57bcd

35
tests/Tests/Loop.hs Normal file
View File

@ -0,0 +1,35 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Tests.Loop
( runFixLoop
, runTailLoop
, runForeverLoop
) where
import Control.Monad (forever)
import Control.Monad.Freer
import Data.Function (fix)
-- | This loops forever as expected
fixLoop :: Member IO r => Eff r ()
fixLoop = fix $ \fxLoop -> do
send $ putStrLn "fixLoop"
fxLoop
runFixLoop :: IO ()
runFixLoop = runM fixLoop
-- | This loops as expected
tailLoop :: Member IO r => Eff r ()
tailLoop = send (putStrLn "tailLoop") >> tailLoop
runTailLoop :: IO ()
runTailLoop = runM tailLoop
-- | This <<loop>>s.
foreverLoop :: Member IO r => Eff r ()
foreverLoop = forever $ send $ putStrLn "loop"
runForeverLoop :: IO ()
runForeverLoop = runM foreverLoop