Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type MyAPI = ("date" :/ Get Day) :<|> (("time" :/ (Capture TimeZone :/ Get ZonedTime)) :<|> ("delayed" :/ (Capture Float :/ Get String)))
- handle_date :: Orc Day
- handle_time :: TimeZone -> Orc ZonedTime
- handle_delayed :: Float -> Orc String
- serve_my_api :: [String] -> Orc String
- servant_main :: IO ()
- data Load (e :: Type) (u :: Type) = forall s.(e ~ s, u ~ ()) => Load
- load :: h `Handles` Load => h ? Ex h Load
- data Save (e :: Type) (u :: Type) = forall s.(e ~ s, u ~ ()) => Save s
- save :: h `Handles` Save => Ex h Save -> h ? ()
- data Edit (e :: Type) (u :: Type) = forall s.(e ~ s, u ~ ()) => Edit (s -> s)
- edit :: (h `Handles` Edit, s ~ Ex h Edit) => (s -> s) -> h ? ()
- 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
- newtype StateHandler (s :: Type) (a :: Type) = StateHandler s
- state_handler :: s -> (StateHandler s a ? a) -> (s, a)
- newtype FStateHandler (h :: Type) (s :: Type) (a :: Type) = FStateHandler s
- f_state_handler :: Monad m => a -> CPS (m (a, b)) ((->) (FStateHandler h a (m (a, b)))) b -> m (a, b)
- data Throw (e :: Type) (u :: Type) = forall err a.(e ~ err, u ~ a) => Throw err
- throw :: h `Handles` Throw => Ex h Throw -> h ? a
- type Except err a = forall h. (h `Handles` Throw, Ex h Throw ~ err) => h ? a
- newtype ExceptHandler (err :: Type) (a :: Type) = ExceptHandler ()
- except_handler :: (ExceptHandler err a ? a) -> Either err a
- catch :: Monad m => (ExceptHandler err a ? a) -> (err -> m a) -> m a
- 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
- ex1 :: StatefulExcept String Int Bool
- newtype StateExceptHandler (err :: Type) (s :: Type) (a :: Type) = SEH s
- state_except_handler :: s -> (StateExceptHandler err s a ? a) -> (s, Either err a)
- effects_demo :: IO ()
- data Cell
- bg_pattern :: [Cell]
- tape_from_pattern :: [Cell] -> Tape Cell
- rule110 :: Sheet2 Cell -> Cell
- ether :: Sheet2 (Sheet2 Cell -> Cell)
- prepare :: [Cell] -> Sheet2 (Sheet2 Cell -> Cell)
- print_automaton :: Int -> Int -> Sheet2 (Sheet2 Cell -> Cell) -> IO ()
- sheets_demo :: IO ()
- sheets_demo_A :: IO ()
- sheets_demo_B :: IO ()
- sheets_demo_blank :: IO ()
- son_a :: [Cell]
- son_b :: [Cell]
- son_c :: [Cell]
- ish2D :: ISheet2 (Int, Int)
- sh2D :: Sheet2 (Int, Int)
- type Grid = Store Sheet2
- type Coord = Counted Nat2 Int
- fromPair :: (Int, Int) -> Coord
- mkGrid :: [Coord] -> Grid Bool
- unGrid :: Grid a -> ISheet2 a
- type Rule = Grid Bool -> Bool
- neighborCoords :: [Coord]
- basicRule :: Rule
- glider :: [Coord]
- blinker :: [Coord]
- beacon :: [Coord]
- at :: [Coord] -> (Int, Int) -> [Coord]
- start :: Grid Bool
- render :: Grid Bool -> String
- tickTime :: Int
- lifeSim :: IO ()
- lifeLoop :: (Grid Bool -> Grid Bool) -> Grid Bool -> IO ()
Documentation
type MyAPI = ("date" :/ Get Day) :<|> (("time" :/ (Capture TimeZone :/ Get ZonedTime)) :<|> ("delayed" :/ (Capture Float :/ Get String))) Source #
handle_date :: Orc Day Source #
servant_main :: IO () Source #
Effects demo.
data Load (e :: Type) (u :: Type) Source #
Operation to load an implicit, dynamic state value.
forall s.(e ~ s, u ~ ()) => Load |
Instances
data Save (e :: Type) (u :: Type) Source #
Operation to save an implicit, dynamic state value.
forall s.(e ~ s, u ~ ()) => Save s |
Instances
data Edit (e :: Type) (u :: Type) Source #
forall s.(e ~ s, u ~ ()) => Edit (s -> s) |
Instances
Handles (StateHandler s a) Edit Source # | |
Defined in Demos type Ex (StateHandler s a) Edit :: j Source # 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 # | |
Defined in Demos | |
type Return (Edit s ()) 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 #
newtype StateHandler (s :: Type) (a :: Type) Source #
An endofunctor corresponding to Stateful
effect handlers.
Instances
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.
Instances
Handles (FStateHandler h s a) Load Source # | |
Defined in Demos type Ex (FStateHandler h s a) Load :: j Source # 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 # | |
Defined in Demos type Ex (FStateHandler h s a) Save :: j Source # 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 # | |
Defined in Demos | |
type Ex (FStateHandler h s a) Save Source # | |
Defined in Demos | |
type Result (FStateHandler h s a) Source # | |
Defined in Demos |
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 #
forall err a.(e ~ err, u ~ a) => Throw err |
Instances
Handles (ExceptHandler err a) Throw Source # | |
Defined in Demos type Ex (ExceptHandler err a) Throw :: j Source # 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 # | |
Defined in Demos type Ex (StateExceptHandler err s a) Throw :: j Source # 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 # | |
Defined in Demos | |
type Ex (StateExceptHandler err s a) Throw Source # | |
Defined in Demos | |
type Return (Throw err 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 err
ors.
newtype ExceptHandler (err :: Type) (a :: Type) Source #
Instances
Handles (ExceptHandler err a) Throw Source # | |
Defined in Demos type Ex (ExceptHandler err a) Throw :: j Source # 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 # | |
Defined in Demos | |
type Result (ExceptHandler err a) Source # | |
Defined in Demos |
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.
newtype StateExceptHandler (err :: Type) (s :: Type) (a :: Type) Source #
Interprets StatefulExcept
err s a
as the type s -> (s, Either err a)
.
SEH s |
Instances
state_except_handler :: s -> (StateExceptHandler err s a ? a) -> (s, Either err a) Source #
effects_demo :: IO () Source #
>>>
effects_demo
(0,Right ()) (0,Left "error")
Sheets demo
bg_pattern :: [Cell] Source #
A background pattern to evaluate in our CA
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.
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 #
sheets_demo_A :: IO () Source #
sheets_demo_B :: IO () Source #
sheets_demo_blank :: IO () Source #
representable indexed sheets ... fiddling
neighborCoords :: [Coord] Source #