Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
UI
Synopsis
- data UI a
- newtype Action space effect a = Action {
- work :: forall r. space (a -> effect r) -> effect r
- mount :: Comonad space => Component IO space (Action space) Console -> IO ()
- type BehaviorOf = Cofree
- behavior :: Functor f => (a -> f a) -> a -> BehaviorOf f a
- unwrap :: ComonadCofree f w => w a -> f (w a)
- type Screen w m = Component m w (Action w) Console
- modify :: ComonadStore s w => (s -> s) -> Action w effect ()
- put :: ComonadStore s w => s -> Action w effect ()
- get :: ComonadStore s w => Action w effect s
- data Event
- glyphCode :: Integral n => Char -> n
- blockGlyph :: Integral n => n
- drawBlock :: Int -> Int -> UI ()
- drawRect :: Int -> Int -> Int -> Int -> UI ()
- screenBorder :: Int -> UI ()
- centerText :: String -> UI ()
- statusText :: String -> UI ()
- width :: UI Int
- height :: UI Int
- type Callback effect action = action effect () -> effect ()
- type Interface effect action view = Callback effect action -> view
- type Component effect space action view = space (Interface effect action view)
- data Console = Console (Event -> IO ()) (UI ())
- move :: Functor space => (a -> b -> effect r) -> Action space effect a -> space b -> effect r
- type Store s = StoreT s Identity
- store :: (s -> a) -> s -> Store s a
- runStore :: Store s a -> (s -> a, s)
- liftIO :: MonadIO m => IO a -> m a
Documentation
DSL based on Termbox2
for UI drawing operations
The decisions to not derive MonadIO
or export the constructor are
deliberate.
newtype Action space effect a Source #
Represents some action performed with or on a given component space
.
These actions have side effects in a base monad.
Instances
Comonad space => MonadTrans (Action space) Source # | |
(Comonad space, MonadIO effect) => MonadIO (Action space effect) Source # | |
Comonad space => Applicative (Action space effect) Source # | |
Defined in UI Methods pure :: a -> Action space effect a Source # (<*>) :: Action space effect (a -> b) -> Action space effect a -> Action space effect b Source # liftA2 :: (a -> b -> c) -> Action space effect a -> Action space effect b -> Action space effect c Source # (*>) :: Action space effect a -> Action space effect b -> Action space effect b Source # (<*) :: Action space effect a -> Action space effect b -> Action space effect a Source # | |
Functor space => Functor (Action space effect) Source # | |
Comonad space => Monad (Action space effect) Source # | |
mount :: Comonad space => Component IO space (Action space) Console -> IO () Source #
Sets up a component for execution and catches exceptions.
type BehaviorOf = Cofree Source #
Defines a space with the behavior of a given base functor.
behavior :: Functor f => (a -> f a) -> a -> BehaviorOf f a Source #
Constructs a space with the behavior of a given base functor.
type Screen w m = Component m w (Action w) Console Source #
Legible alias for a common component type.
modify :: ComonadStore s w => (s -> s) -> Action w effect () Source #
Action
for components built from a ComonadStore
: modifies state.
put :: ComonadStore s w => s -> Action w effect () Source #
Action
for components built from a ComonadStore
: overwrites state.
get :: ComonadStore s w => Action w effect s Source #
Action
for components built from a ComonadStore
: loads state.
blockGlyph :: Integral n => n Source #
screenBorder :: Int -> UI () Source #
centerText :: String -> UI () Source #
statusText :: String -> UI () Source #
A console view.
move :: Functor space => (a -> b -> effect r) -> Action space effect a -> space b -> effect r Source #
Carries out an Action
in a given space yielding a result with side
effects in a effect monad.
liftIO :: MonadIO m => IO a -> m a Source #
Lift a computation from the IO
monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO
is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted
, we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO ()
and
.IO
()
Luckily, we know of a function that takes an
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3