Skip to content

Instantly share code, notes, and snippets.

@ethul
Created August 9, 2015 16:12
Show Gist options
  • Save ethul/ee9a7ef6238903df4579 to your computer and use it in GitHub Desktop.
Save ethul/ee9a7ef6238903df4579 to your computer and use it in GitHub Desktop.
module Forever where
import Prelude
import Control.Monad.Eff
import Control.Monad.Eff.Console
import Control.Monad.Free
import Control.Monad.Rec.Class (forever)
import Data.NaturalTransformation
data TeletypeF a = PutStrLn String a
type Teletype a = Free TeletypeF a
putStrLn :: String -> Teletype Unit
putStrLn s = liftF (PutStrLn s unit)
teletypeN :: forall e. NaturalTransformation TeletypeF (Eff (console :: CONSOLE))
teletypeN (PutStrLn s a) = const a <$> pure s
run :: forall a. Teletype a -> Eff (console :: CONSOLE) a
run = foldFree teletypeN
program = forever $ putStrLn "Forever"
main = run program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment