-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Hyperfunctions -- @package hyperfunctions @version 0 -- | Hyperfunctions as an explicit nu form, but using a representable -- functor to describe the state space of the hyperfunction. This permits -- memoization but doesn't require it. -- -- If we start with a 'function with state' (x -> a) -> x -> -- b we can view it as either (x -> a, x) -> b wich -- is a Store x Cokleisli morphism or as φ :: x -> (x -- -> a) -> b which given H a b x = (x -> a) -> -- b is a (H a b)-coalgebra: (x, φ) . Given that -- we can think of anamorphisms of this 'function with state' as giving -- us a fixed point for H a b and the morphism to the final -- coalgebra @(Hyper a b, ana φ) is unique (by definition). -- -- A representable functor f is isomorphic to (->) -- (Rep f). ((->) x) is an obvious selection for -- such a representable functor, so if we switch out the functions from -- x in the above, for a representable functor with x -- as its representation we get opportunities for memoization on the -- internal 'state space' of our hyperfunctions. module Control.Monad.Hyper.Rep -- | Represented Hyperfunctions -- -- arr is a faithful functor, so -- -- arr f ≡ arr g implies f ≡ g data Hyper a b Hyper :: g (g a -> b) -> Rep g -> Hyper a b ana :: (x -> (x -> a) -> b) -> x -> Hyper a b -- |
-- cata phi (push f h) ≡ phi $ \g -> f $ g (cata phi h) --cata :: (((y -> a) -> b) -> y) -> Hyper a b -> y -- | Memoizing catamorphism cata' :: Representable f => ((f a -> b) -> Rep f) -> Hyper a b -> Rep f -- |
-- arr f ≡ push f (arr f) -- invoke (push f q) k ≡ f (invoke k q) -- push f p . push g q ≡ push (f . g) (p . q) --push :: (a -> b) -> Hyper a b -> Hyper a b -- | Unroll a hyperfunction unroll :: Hyper a b -> (Hyper a b -> a) -> b -- | Re-roll a hyperfunction using Lambek's lemma. roll :: ((Hyper a b -> a) -> b) -> Hyper a b invoke :: Hyper a b -> Hyper b a -> b uninvoke :: (Hyper b a -> b) -> Hyper a b -- |
-- run f ≡ invoke f id -- run (arr f) ≡ fix f -- run (push f q) ≡ f (run q) -- run (push f p . q) ≡ f (run (q . p)) = f (invoke q p) --run :: Hyper a a -> a -- |
-- project . arr ≡ id -- project h a ≡ invoke h (pure a) -- project (push f q) ≡ f --project :: Hyper a b -> a -> b -- | Under "nice" conditions -- --
-- fold . build ≡ id --fold :: [a] -> (a -> b -> c) -> c -> Hyper b c build :: (forall b c. (a -> b -> c) -> c -> Hyper b c) -> [a] instance Costrong Hyper instance Strong Hyper instance Profunctor Hyper instance MonadZip (Hyper a) instance Monad (Hyper a) instance Applicative (Hyper a) instance Functor (Hyper a) instance ArrowLoop Hyper instance Arrow Hyper instance Category Hyper module Control.Monad.Hyper -- |
-- invoke f g ≡ run (f . g) -- arr f ≡ push f (arr f) -- invoke id id ≡ _|_ ---- -- arr is a faithful functor, so arr f ≡ arr -- g implies f ≡ g newtype Hyper a b Hyper :: (Hyper b a -> b) -> Hyper a b invoke :: Hyper a b -> Hyper b a -> b unroll :: Hyper a b -> (Hyper a b -> a) -> b roll :: ((Hyper a b -> a) -> b) -> Hyper a b ana :: (x -> (x -> a) -> b) -> x -> Hyper a b -- | From "Generalizing the augment combinator" by Ghani, Uustali and Vene. -- --
-- cata phi (push f h) ≡ phi $ \g -> f $ g (cata phi h) --cata :: (((x -> a) -> b) -> x) -> Hyper a b -> x -- |
-- push f p . push g q ≡ push (f . g) (p . q) -- invoke (push f p) q ≡ f (invoke q p) --push :: (a -> b) -> Hyper a b -> Hyper a b -- |
-- run (arr f) ≡ fix f -- run (push f q) ≡ f (run q) -- run (push f p . q) ≡ f (run (q . p)) = f (invoke q p) --run :: Hyper a a -> a -- |
-- project (push f q) ≡ f ---- -- project is a left inverse for arr: -- --
-- project . arr ≡ id --project :: Hyper a b -> a -> b fold :: [a] -> (a -> b -> c) -> c -> Hyper b c -- | Under nice conditions: -- --
-- fold . build ≡ id --build :: (forall b c. (a -> b -> c) -> c -> Hyper b c) -> [a] instance MonadZip (Hyper a) instance Monad (Hyper a) instance Applicative (Hyper a) instance Functor (Hyper a) instance Costrong Hyper instance Strong Hyper instance ArrowLoop Hyper instance Arrow Hyper instance Profunctor Hyper instance Category Hyper