1{-# LANGUAGE FlexibleContexts #-}
3-- This example is adapted from Gabriel Gonzalez's pipes-concurrency package.
4-- https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html
7import Control.Concurrent (threadDelay)
8import Control.Monad (when)
9import Control.Monad.IO.Class (MonadIO(liftIO))
10import Control.Monad.State (MonadState, get, modify, runStateT)
11import Data.Semigroup (cycle1)
13data Event = Harm Int | Heal Int | Quit deriving (Show)
15userAction :: MonadIO m => SerialT m Event
16userAction = cycle1 $ liftIO askUser
21 "potion" -> return (Heal 10)
23 _ -> putStrLn "What?" >> askUser
25acidRain :: MonadIO m => SerialT m Event
26acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
28game :: (MonadAsync m, MonadState Int m) => SerialT m ()
30 event <- userAction `parallel` acidRain
32 Harm n -> modify $ \h -> h - n
33 Heal n -> modify $ \h -> h + n
37 when (h <= 0) $ fail "You die!"
38 liftIO $ putStrLn $ "Health = " ++ show h
42 putStrLn "Your health is deteriorating due to acid rain,\
43 \ type \"potion\" or \"quit\""
44 _ <- runStateT (runStream game) 60
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list