garden
Safe HaskellSafe-Inferred
LanguageHaskell2010

UI

Synopsis

Documentation

data UI a Source #

DSL based on Termbox2 for UI drawing operations The decisions to not derive MonadIO or export the constructor are deliberate.

Instances

Instances details
Applicative UI Source # 
Instance details

Defined in UI

Methods

pure :: a -> UI a Source #

(<*>) :: UI (a -> b) -> UI a -> UI b Source #

liftA2 :: (a -> b -> c) -> UI a -> UI b -> UI c Source #

(*>) :: UI a -> UI b -> UI b Source #

(<*) :: UI a -> UI b -> UI a Source #

Functor UI Source # 
Instance details

Defined in UI

Methods

fmap :: (a -> b) -> UI a -> UI b Source #

(<$) :: a -> UI b -> UI a Source #

Monad UI Source # 
Instance details

Defined in UI

Methods

(>>=) :: UI a -> (a -> UI b) -> UI b Source #

(>>) :: UI a -> UI b -> UI b Source #

return :: a -> UI a Source #

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.

Constructors

Action 

Fields

  • work :: forall r. space (a -> effect r) -> effect r
     

Instances

Instances details
Comonad space => MonadTrans (Action space) Source # 
Instance details

Defined in UI

Methods

lift :: Monad m => m a -> Action space m a Source #

(Comonad space, MonadIO effect) => MonadIO (Action space effect) Source # 
Instance details

Defined in UI

Methods

liftIO :: IO a -> Action space effect a Source #

Comonad space => Applicative (Action space effect) Source # 
Instance details

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 # 
Instance details

Defined in UI

Methods

fmap :: (a -> b) -> Action space effect a -> Action space effect b Source #

(<$) :: a -> Action space effect b -> Action space effect a Source #

Comonad space => Monad (Action space effect) Source # 
Instance details

Defined in UI

Methods

(>>=) :: Action space effect a -> (a -> Action space effect b) -> Action space effect b Source #

(>>) :: Action space effect a -> Action space effect b -> Action space effect b Source #

return :: a -> Action space effect a Source #

mount :: Comonad space => Activity space IO -> 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.

unwrap :: ComonadCofree f w => w a -> f (w a) #

type Activity space effect = Component effect space (Action space) Console Source #

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.

newtype Event Source #

FIXME this newtype wrapper is purely due to laziness and a better Event type should be created so the tb2 abstraction does not leak.

Constructors

Event Tb2Event 

Instances

Instances details
Show Event Source # 
Instance details

Defined in UI

Eq Event Source # 
Instance details

Defined in UI

Methods

(==) :: Event -> Event -> Bool Source #

(/=) :: Event -> Event -> Bool Source #

drawBlock :: Int -> Int -> UI () Source #

drawRect :: Int -> Int -> Int -> Int -> UI () Source #

type Callback effect action = action effect () -> effect () Source #

type Interface effect action view = Callback effect action -> view Source #

type Component effect space action view = space (Interface effect action view) Source #

data Console Source #

A console view.

Constructors

Console 

Fields

  • (Event -> IO ())

    Awaits incoming events.

  • (UI ())

    Renders output when called.

move :: Functor space => (a -> b -> effect r) -> Action space effect a -> space b -> effect r Source #

Carries out an Action in a space yielding a result with side effects.

hoist :: (forall x. w x -> v x) -> Action v effect a -> Action w effect a Source #

Hoist an Action for one space into a different space contravariantly.

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 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

Expand
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 liftIO, we would have ended up with this error:

• 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 IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:

> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3