garden
Safe HaskellSafe-Inferred
LanguageHaskell2010

Demos

Synopsis

Documentation

type MyAPI = ("date" :/ Get Day) :<|> (("time" :/ (Capture TimeZone :/ Get ZonedTime)) :<|> ("delayed" :/ (Capture Float :/ Get String))) Source #

Effects demo.

data Load (e :: Type) (u :: Type) Source #

Operation to load an implicit, dynamic state value.

Constructors

forall s.(e ~ s, u ~ ()) => Load 

Instances

Instances details
Handles (StateHandler s a) Load Source #

StateHandler fulfills the Load operation.

Instance details

Defined in Demos

Associated Types

type Ex (StateHandler s a) Load :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateHandler s a) Load => Load e u -> (Return (Load e u) -> StateHandler s a -> Result (StateHandler s a)) -> StateHandler s a -> Result (StateHandler s a) Source #

Handles (FStateHandler h s a) Load Source # 
Instance details

Defined in Demos

Associated Types

type Ex (FStateHandler h s a) Load :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (FStateHandler h s a) Load => Load e u -> (Return (Load e u) -> FStateHandler h s a -> Result (FStateHandler h s a)) -> FStateHandler h s a -> Result (FStateHandler h s a) Source #

Handles (StateExceptHandler err s a) Load Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateExceptHandler err s a) Load :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateExceptHandler err s a) Load => Load e u -> (Return (Load e u) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a)) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a) Source #

type Ex (StateHandler s a) Load Source # 
Instance details

Defined in Demos

type Ex (StateHandler s a) Load = s
type Ex (FStateHandler h s a) Load Source # 
Instance details

Defined in Demos

type Ex (FStateHandler h s a) Load = s
type Ex (StateExceptHandler err s a) Load Source # 
Instance details

Defined in Demos

type Ex (StateExceptHandler err s a) Load = s
type Return (Load s ()) Source # 
Instance details

Defined in Demos

type Return (Load s ()) = s

data Save (e :: Type) (u :: Type) Source #

Operation to save an implicit, dynamic state value.

Constructors

forall s.(e ~ s, u ~ ()) => Save s 

Instances

Instances details
Handles (StateHandler s a) Save Source #

StateHandler also fulfills the Save operation.

Instance details

Defined in Demos

Associated Types

type Ex (StateHandler s a) Save :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateHandler s a) Save => Save e u -> (Return (Save e u) -> StateHandler s a -> Result (StateHandler s a)) -> StateHandler s a -> Result (StateHandler s a) Source #

Handles (FStateHandler h s a) Save Source # 
Instance details

Defined in Demos

Associated Types

type Ex (FStateHandler h s a) Save :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (FStateHandler h s a) Save => Save e u -> (Return (Save e u) -> FStateHandler h s a -> Result (FStateHandler h s a)) -> FStateHandler h s a -> Result (FStateHandler h s a) Source #

Handles (StateExceptHandler err s a) Save Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateExceptHandler err s a) Save :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateExceptHandler err s a) Save => Save e u -> (Return (Save e u) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a)) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a) Source #

type Ex (StateHandler s a) Save Source # 
Instance details

Defined in Demos

type Ex (StateHandler s a) Save = s
type Ex (FStateHandler h s a) Save Source # 
Instance details

Defined in Demos

type Ex (FStateHandler h s a) Save = s
type Ex (StateExceptHandler err s a) Save Source # 
Instance details

Defined in Demos

type Ex (StateExceptHandler err s a) Save = s
type Return (Save s ()) Source # 
Instance details

Defined in Demos

type Return (Save s ()) = ()

save :: h `Handles` Save => Ex h Save -> h ? () Source #

data Edit (e :: Type) (u :: Type) Source #

Constructors

forall s.(e ~ s, u ~ ()) => Edit (s -> s) 

Instances

Instances details
Handles (StateHandler s a) Edit Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateHandler s a) Edit :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateHandler s a) Edit => Edit e u -> (Return (Edit e u) -> StateHandler s a -> Result (StateHandler s a)) -> StateHandler s a -> Result (StateHandler s a) Source #

type Ex (StateHandler s a) Edit Source # 
Instance details

Defined in Demos

type Ex (StateHandler s a) Edit = s
type Return (Edit s ()) Source # 
Instance details

Defined in Demos

type Return (Edit s ()) = ()

edit :: (h `Handles` Edit, s ~ Ex h Edit) => (s -> s) -> h ? () Source #

type Stateful s a = forall h. (h `Handles` Load, h `Handles` Save, h `Handles` Edit, s ~ Ex h Load, s ~ Ex h Save, s ~ Ex h Edit) => h ? a Source #

Computations which may load or save an implicit, dynamic state value.

newtype StateHandler (s :: Type) (a :: Type) Source #

An endofunctor corresponding to Stateful effect handlers.

Constructors

StateHandler s 

Instances

Instances details
Handles (StateHandler s a) Edit Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateHandler s a) Edit :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateHandler s a) Edit => Edit e u -> (Return (Edit e u) -> StateHandler s a -> Result (StateHandler s a)) -> StateHandler s a -> Result (StateHandler s a) Source #

Handles (StateHandler s a) Load Source #

StateHandler fulfills the Load operation.

Instance details

Defined in Demos

Associated Types

type Ex (StateHandler s a) Load :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateHandler s a) Load => Load e u -> (Return (Load e u) -> StateHandler s a -> Result (StateHandler s a)) -> StateHandler s a -> Result (StateHandler s a) Source #

Handles (StateHandler s a) Save Source #

StateHandler also fulfills the Save operation.

Instance details

Defined in Demos

Associated Types

type Ex (StateHandler s a) Save :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateHandler s a) Save => Save e u -> (Return (Save e u) -> StateHandler s a -> Result (StateHandler s a)) -> StateHandler s a -> Result (StateHandler s a) Source #

type Ex (StateHandler s a) Edit Source # 
Instance details

Defined in Demos

type Ex (StateHandler s a) Edit = s
type Ex (StateHandler s a) Load Source # 
Instance details

Defined in Demos

type Ex (StateHandler s a) Load = s
type Ex (StateHandler s a) Save Source # 
Instance details

Defined in Demos

type Ex (StateHandler s a) Save = s
type Result (StateHandler s a) Source # 
Instance details

Defined in Demos

type Result (StateHandler s a) = (s, a)

state_handler :: s -> (StateHandler s a ? a) -> (s, a) Source #

Handles Stateful computations. Usage:

>>> let (nine, three) = state_handler 3 (load >>= \n -> save (n * n) >> return n)
>>> nine
9
>>> three
3

newtype FStateHandler (h :: Type) (s :: Type) (a :: Type) Source #

A "forwarding" state-handler.

Constructors

FStateHandler s 

Instances

Instances details
Handles (FStateHandler h s a) Load Source # 
Instance details

Defined in Demos

Associated Types

type Ex (FStateHandler h s a) Load :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (FStateHandler h s a) Load => Load e u -> (Return (Load e u) -> FStateHandler h s a -> Result (FStateHandler h s a)) -> FStateHandler h s a -> Result (FStateHandler h s a) Source #

Handles (FStateHandler h s a) Save Source # 
Instance details

Defined in Demos

Associated Types

type Ex (FStateHandler h s a) Save :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (FStateHandler h s a) Save => Save e u -> (Return (Save e u) -> FStateHandler h s a -> Result (FStateHandler h s a)) -> FStateHandler h s a -> Result (FStateHandler h s a) Source #

type Ex (FStateHandler h s a) Load Source # 
Instance details

Defined in Demos

type Ex (FStateHandler h s a) Load = s
type Ex (FStateHandler h s a) Save Source # 
Instance details

Defined in Demos

type Ex (FStateHandler h s a) Save = s
type Result (FStateHandler h s a) Source # 
Instance details

Defined in Demos

type Result (FStateHandler h s a) = a

f_state_handler :: Monad m => a -> CPS (m (a, b)) ((->) (FStateHandler h a (m (a, b)))) b -> m (a, b) Source #

A state-handler which forwards unsupported operations to another handler. Usage:

>>> (nine, unit) <- f_state_handler 3 (load >>= \n -> save (n * n))
>>> nine
9
>>> unit
()

data Throw (e :: Type) (u :: Type) Source #

Operation to throw a specified value in Exceptional circumstances.

Constructors

forall err a.(e ~ err, u ~ a) => Throw err 

Instances

Instances details
Handles (ExceptHandler err a) Throw Source # 
Instance details

Defined in Demos

Associated Types

type Ex (ExceptHandler err a) Throw :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (ExceptHandler err a) Throw => Throw e u -> (Return (Throw e u) -> ExceptHandler err a -> Result (ExceptHandler err a)) -> ExceptHandler err a -> Result (ExceptHandler err a) Source #

Handles (StateExceptHandler err s a) Throw Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateExceptHandler err s a) Throw :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateExceptHandler err s a) Throw => Throw e u -> (Return (Throw e u) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a)) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a) Source #

type Ex (ExceptHandler err a) Throw Source # 
Instance details

Defined in Demos

type Ex (ExceptHandler err a) Throw = err
type Ex (StateExceptHandler err s a) Throw Source # 
Instance details

Defined in Demos

type Ex (StateExceptHandler err s a) Throw = err
type Return (Throw err a) Source # 
Instance details

Defined in Demos

type Return (Throw err a) = a

throw :: h `Handles` Throw => Ex h Throw -> h ? a Source #

type Except err a = forall h. (h `Handles` Throw, Ex h Throw ~ err) => h ? a Source #

A computation which evaluates to a Except for errors.

newtype ExceptHandler (err :: Type) (a :: Type) Source #

This handler Results in Either an err value or answer a.

Constructors

ExceptHandler () 

Instances

Instances details
Handles (ExceptHandler err a) Throw Source # 
Instance details

Defined in Demos

Associated Types

type Ex (ExceptHandler err a) Throw :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (ExceptHandler err a) Throw => Throw e u -> (Return (Throw e u) -> ExceptHandler err a -> Result (ExceptHandler err a)) -> ExceptHandler err a -> Result (ExceptHandler err a) Source #

type Ex (ExceptHandler err a) Throw Source # 
Instance details

Defined in Demos

type Ex (ExceptHandler err a) Throw = err
type Result (ExceptHandler err a) Source # 
Instance details

Defined in Demos

type Result (ExceptHandler err a) = Either err a

except_handler :: (ExceptHandler err a ? a) -> Either err a Source #

Evaluates an exception-handling computation.

catch :: Monad m => (ExceptHandler err a ? a) -> (err -> m a) -> m a Source #

A more conventional throw-receiving idiom.

type StatefulExcept err s a = forall h. (h `Handles` Load, Ex h Load ~ s, h `Handles` Save, Ex h Save ~ s, h `Handles` Throw, Ex h Throw ~ err) => h ? a Source #

With a little elbow grease this could be derived automatically.

ex1 :: StatefulExcept String Int Bool Source #

Example computation combining Stateful and Except effects, which were defined in a separate module. The parlor trick here is that this type-checks without defining any handlers, combining 3 operations from 2 distinct effect types with existing, independent handlers.

newtype StateExceptHandler (err :: Type) (s :: Type) (a :: Type) Source #

Interprets StatefulExcept err s a as the type s -> (s, Either err a).

Constructors

SEH s 

Instances

Instances details
Handles (StateExceptHandler err s a) Load Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateExceptHandler err s a) Load :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateExceptHandler err s a) Load => Load e u -> (Return (Load e u) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a)) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a) Source #

Handles (StateExceptHandler err s a) Save Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateExceptHandler err s a) Save :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateExceptHandler err s a) Save => Save e u -> (Return (Save e u) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a)) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a) Source #

Handles (StateExceptHandler err s a) Throw Source # 
Instance details

Defined in Demos

Associated Types

type Ex (StateExceptHandler err s a) Throw :: j Source #

Methods

clause :: forall (e :: j) (u :: k). e ~ Ex (StateExceptHandler err s a) Throw => Throw e u -> (Return (Throw e u) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a)) -> StateExceptHandler err s a -> Result (StateExceptHandler err s a) Source #

type Ex (StateExceptHandler err s a) Load Source # 
Instance details

Defined in Demos

type Ex (StateExceptHandler err s a) Load = s
type Ex (StateExceptHandler err s a) Save Source # 
Instance details

Defined in Demos

type Ex (StateExceptHandler err s a) Save = s
type Ex (StateExceptHandler err s a) Throw Source # 
Instance details

Defined in Demos

type Ex (StateExceptHandler err s a) Throw = err
type Result (StateExceptHandler err s a) Source # 
Instance details

Defined in Demos

type Result (StateExceptHandler err s a) = (s, Either err a)

state_except_handler :: s -> (StateExceptHandler err s a ? a) -> (s, Either err a) Source #

A handler for both Stateful and Exceptional computations. If the typeclass instances above are the case-statements for different effects, this is more or less the case-statement for "return" / termination.

effects_demo :: IO () Source #

>>> effects_demo
(0,Right ())
(0,Left "error")

Sheets demo

data Cell Source #

A Cell is either "on" (I) or "off" (O).

Constructors

I 
O 

Instances

Instances details
Show Cell Source # 
Instance details

Defined in Demos

Eq Cell Source # 
Instance details

Defined in Demos

Methods

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

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

bg_pattern :: [Cell] Source #

A background pattern to evaluate in our CA

tape_from_pattern :: [Cell] -> Tape Cell Source #

Lifts a list of Cells into a Tape.

rule110 :: Sheet2 Cell -> Cell Source #

The 2-dimensional cellular automaton "rule 110." To evaluate one time-step, each cell along with its immediate left and right neighbors is used to determine that cell's next value (proceed below). I believe it is the simplest Turing-complete CA.

ether :: Sheet2 (Sheet2 Cell -> Cell) Source #

A 2-dimensional sheet (Sheet2). Each Cell of the Sheet2 is a function which transforms a Sheet2 of Cells into a new value for that Cell.

prepare :: [Cell] -> Sheet2 (Sheet2 Cell -> Cell) Source #

This lifts a pattern of Cell values into a 2-dimensional spreadsheet.

print_automaton :: Int -> Int -> Sheet2 (Sheet2 Cell -> Cell) -> IO () Source #

Prints a given slice of the output stream, which represents the evolution of the 2-D spreadsheet over time.

sheets_demo :: IO () Source #

Constructs an interesting-ish Rule 110 scenario and prints a slice of the output stream, showing the time-evolution of a 2-D spreadsheet. This aims son_a and son_b at each other. They collide, entangle, and then disentangle in swapped places.

son_a :: [Cell] Source #

Some Cell patterns which happen to be interesting in Rule 110.

son_b :: [Cell] Source #

Some Cell patterns which happen to be interesting in Rule 110.

son_c :: [Cell] Source #

Some Cell patterns which happen to be interesting in Rule 110.

representable indexed sheets ... fiddling

type Grid = Store Sheet2 Source #

at :: [Coord] -> (Int, Int) -> [Coord] Source #