mirror of
https://github.com/lexi-lambda/freer-simple.git
synced 2024-12-23 22:23:27 +03:00
loop example
This commit is contained in:
parent
07ee1289bc
commit
7094f57bcd
35
tests/Tests/Loop.hs
Normal file
35
tests/Tests/Loop.hs
Normal 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
|
Loading…
Reference in New Issue
Block a user