[initialized ekmett@gmail.com**20090414021340 Ignore-this: 3019a909233617d3b014330178cd80a3 ] { adddir ./doc adddir ./doc/html adddir ./doc/html/monad-ran addfile ./doc/html/monad-ran/Control-Monad-Ran.html hunk ./doc/html/monad-ran/Control-Monad-Ran.html 1 + + +Control.Monad.Ran
 monad-ran-0.0.6: Implementations of common monads and monad transformers as right Kan extensionsSource codeContentsIndex
Control.Monad.Ran
Documentation
data Yoneda f a Source
Constructors
Yoneda
getYoneda :: forall b. (a -> b) -> f b
show/hide Instances
data Codensity f a Source
Constructors
Codensity
getCodensity :: forall b. (a -> f b) -> f b
show/hide Instances
data Ran m a Source
Constructors
Ran
getRan :: forall b. (a -> G m b) -> H m b
class Monad f => RMonad f whereSource
Associated Types
type G f :: * -> *Source
type H f :: * -> *Source
Methods
toRan :: f a -> Ran f aSource
fromRan :: Ran f a -> f aSource
show/hide Instances
toRan :: RMonad f => f a -> Ran f aSource
fromRan :: RMonad f => Ran f a -> f aSource
Produced by Haddock version 2.3.0
addfile ./doc/html/monad-ran/doc-index.html hunk ./doc/html/monad-ran/doc-index.html 1 + + +monad-ran-0.0.6: Implementations of common monads and monad transformers as right Kan extensions (Index)
 monad-ran-0.0.6: Implementations of common monads and monad transformers as right Kan extensionsContentsIndex
Search:
Codensity
1 (Type/Class)
2 (Data Constructor)
fromRan
G
getCodensity
getRan
getYoneda
H
Ran
1 (Type/Class)
2 (Data Constructor)
RMonad
toRan
Yoneda
1 (Type/Class)
2 (Data Constructor)
addfile ./doc/html/monad-ran/haddock-util.js hunk ./doc/html/monad-ran/haddock-util.js 1 +// Haddock JavaScript utilities +function toggle(button,id) +{ + var n = document.getElementById(id).style; + if (n.display == "none") + { + button.src = "minus.gif"; + n.display = "block"; + } + else + { + button.src = "plus.gif"; + n.display = "none"; + } +} + + +var max_results = 75; // 50 is not enough to search for map in the base libraries +var shown_range = null; +var last_search = null; + +function quick_search() +{ + perform_search(false); +} + +function full_search() +{ + perform_search(true); +} + + +function perform_search(full) +{ + var text = document.getElementById("searchbox").value.toLowerCase(); + if (text == last_search && !full) return; + last_search = text; + + var table = document.getElementById("indexlist"); + var status = document.getElementById("searchmsg"); + var children = table.firstChild.childNodes; + + // first figure out the first node with the prefix + var first = bisect(-1); + var last = (first == -1 ? -1 : bisect(1)); + + if (first == -1) + { + table.className = ""; + status.innerHTML = "No results found, displaying all"; + } + else if (first == 0 && last == children.length - 1) + { + table.className = ""; + status.innerHTML = ""; + } + else if (last - first >= max_results && !full) + { + table.className = ""; + status.innerHTML = "More than " + max_results + ", press Search to display"; + } + else + { + // decide what you need to clear/show + if (shown_range) + setclass(shown_range[0], shown_range[1], "indexrow"); + setclass(first, last, "indexshow"); + shown_range = [first, last]; + table.className = "indexsearch"; + status.innerHTML = ""; + } + + + function setclass(first, last, status) + { + for (var i = first; i <= last; i++) + { + children[i].className = status; + } + } + + + // do a binary search, treating 0 as ... + // return either -1 (no 0's found) or location of most far match + function bisect(dir) + { + var first = 0, finish = children.length - 1; + var mid, success = false; + + while (finish - first > 3) + { + mid = Math.floor((finish + first) / 2); + + var i = checkitem(mid); + if (i == 0) i = dir; + if (i == -1) + finish = mid; + else + first = mid; + } + var a = (dir == 1 ? first : finish); + var b = (dir == 1 ? finish : first); + for (var i = b; i != a - dir; i -= dir) + { + if (checkitem(i) == 0) return i; + } + return -1; + } + + + // from an index, decide what the result is + // 0 = match, -1 is lower, 1 is higher + function checkitem(i) + { + var s = getitem(i).toLowerCase().substr(0, text.length); + if (s == text) return 0; + else return (s > text ? -1 : 1); + } + + + // from an index, get its string + // this abstracts over alternates + function getitem(i) + { + for ( ; i >= 0; i--) + { + var s = children[i].firstChild.firstChild.data; + if (s.indexOf(' ') == -1) + return s; + } + return ""; // should never be reached + } +} addfile ./doc/html/monad-ran/haddock.css hunk ./doc/html/monad-ran/haddock.css 1 +/* -------- Global things --------- */ + +BODY { + background-color: #ffffff; + color: #000000; + font-family: sans-serif; + } + +A:link { color: #0000e0; text-decoration: none } +A:visited { color: #0000a0; text-decoration: none } +A:hover { background-color: #e0e0ff; text-decoration: none } + +TABLE.vanilla { + width: 100%; + border-width: 0px; + /* I can't seem to specify cellspacing or cellpadding properly using CSS... */ +} + +TABLE.vanilla2 { + border-width: 0px; +} + +/* font is a little too small in MSIE */ +TT { font-size: 100%; } +PRE { font-size: 100%; } + +LI P { margin: 0pt } + +TD { + border-width: 0px; +} + +TABLE.narrow { + border-width: 0px; +} + +TD.s8 { height: 8px; } +TD.s15 { height: 15px; } + +SPAN.keyword { text-decoration: underline; } + +/* Resize the buttom image to match the text size */ +IMG.coll { width : 0.75em; height: 0.75em; margin-bottom: 0; margin-right: 0.5em } + +/* --------- Contents page ---------- */ + +DIV.node { + padding-left: 3em; +} + +DIV.cnode { + padding-left: 1.75em; +} + +SPAN.pkg { + position: absolute; + left: 50em; +} + +/* --------- Documentation elements ---------- */ + +TD.children { + padding-left: 25px; + } + +TD.synopsis { + padding: 2px; + background-color: #f0f0f0; + font-family: monospace + } + +TD.decl { + padding: 2px; + background-color: #f0f0f0; + font-family: monospace; + vertical-align: top; + } + +TD.topdecl { + padding: 2px; + background-color: #f0f0f0; + font-family: monospace; + vertical-align: top; +} + +TABLE.declbar { + border-spacing: 0px; + } + +TD.declname { + width: 100%; + } + +TD.declbut { + padding-left: 5px; + padding-right: 5px; + border-left-width: 1px; + border-left-color: #000099; + border-left-style: solid; + white-space: nowrap; + font-size: small; + } + +/* + arg is just like decl, except that wrapping is not allowed. It is + used for function and constructor arguments which have a text box + to the right, where if wrapping is allowed the text box squashes up + the declaration by wrapping it. +*/ +TD.arg { + padding: 2px; + background-color: #f0f0f0; + font-family: monospace; + vertical-align: top; + white-space: nowrap; + } + +TD.recfield { padding-left: 20px } + +TD.doc { + padding-top: 2px; + padding-left: 10px; + } + +TD.ndoc { + padding: 2px; + } + +TD.rdoc { + padding: 2px; + padding-left: 10px; + width: 100%; + } + +TD.body { + padding-left: 10px + } + +TD.pkg { + width: 100%; + padding-left: 10px +} + +TABLE.indexsearch TR.indexrow { + display: none; +} +TABLE.indexsearch TR.indexshow { + display: table-row; +} + +TD.indexentry { + vertical-align: top; + padding-right: 10px + } + +TD.indexannot { + vertical-align: top; + padding-left: 20px; + white-space: nowrap + } + +TD.indexlinks { + width: 100% + } + +/* ------- Section Headings ------- */ + +TD.section1 { + padding-top: 15px; + font-weight: bold; + font-size: 150% + } + +TD.section2 { + padding-top: 10px; + font-weight: bold; + font-size: 130% + } + +TD.section3 { + padding-top: 5px; + font-weight: bold; + font-size: 110% + } + +TD.section4 { + font-weight: bold; + font-size: 100% + } + +/* -------------- The title bar at the top of the page */ + +TD.infohead { + color: #ffffff; + font-weight: bold; + padding-right: 10px; + text-align: left; +} + +TD.infoval { + color: #ffffff; + padding-right: 10px; + text-align: left; +} + +TD.topbar { + background-color: #000099; + padding: 5px; +} + +TD.title { + color: #ffffff; + padding-left: 10px; + width: 100% + } + +TD.topbut { + padding-left: 5px; + padding-right: 5px; + border-left-width: 1px; + border-left-color: #ffffff; + border-left-style: solid; + white-space: nowrap; + } + +TD.topbut A:link { + color: #ffffff + } + +TD.topbut A:visited { + color: #ffff00 + } + +TD.topbut A:hover { + background-color: #6060ff; + } + +TD.topbut:hover { + background-color: #6060ff + } + +TD.modulebar { + background-color: #0077dd; + padding: 5px; + border-top-width: 1px; + border-top-color: #ffffff; + border-top-style: solid; + } + +/* --------- The page footer --------- */ + +TD.botbar { + background-color: #000099; + color: #ffffff; + padding: 5px + } +TD.botbar A:link { + color: #ffffff; + text-decoration: underline + } +TD.botbar A:visited { + color: #ffff00 + } +TD.botbar A:hover { + background-color: #6060ff + } + addfile ./doc/html/monad-ran/haskell_icon.gif binary ./doc/html/monad-ran/haskell_icon.gif oldhex * newhex *47494638376110001000f70f00000000800000008000808000000080800080008080c0c0c08080 *80ff000000ff00ffff000000ffff00ff00ffffffffff0000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *000000000000000000000000000000000000000000000000000000000000000000000000000000 *0021f90401000000002c000000001000100007086c0001007840b0a0418202073e38b0b021c387 *07143e2440c0a143040e091cd0787021c686151f84347800e343901d4b12646870e44a930d0952 *3ca832a6cc990555b2bc2992e4c79d3847ea2c88b3a7c89a2c8b8aa43874e941a60810003840b5 *aa55aa511346ddca75abc080003b addfile ./doc/html/monad-ran/index.html hunk ./doc/html/monad-ran/index.html 1 + + +monad-ran-0.0.6: Implementations of common monads and monad transformers as right Kan extensions
 monad-ran-0.0.6: Implementations of common monads and monad transformers as right Kan extensionsContentsIndex
monad-ran-0.0.6: Implementations of common monads and monad transformers as right Kan extensions
. +
Modules
show/hideControl
show/hideMonad
Control.Monad.Ran
Produced by Haddock version 2.3.0
addfile ./doc/html/monad-ran/minus.gif binary ./doc/html/monad-ran/minus.gif oldhex * newhex *47494638396109000900910000fefefe8282820202020000002c00000000090009000002118c8f *a00bc6eb5e0b40583b6596f1a11f14003b addfile ./doc/html/monad-ran/monad-ran.haddock binary ./doc/html/monad-ran/monad-ran.haddock oldhex * newhex *0d0cface000400000000000003c5000000000000025f0e00000000000000000000000000000000 *000000000000000100000000000000010000000000000000000000000000000100000000000000 *020000000000000000000000000000000100000000000000030000000000000000000000000000 *000100000000000000040000000000000000000000000000000100000000000000050000000000 *000000000000000000000100000000000000060000000000000000000000000000000100000000 *000000070000000000000000000000000000000100000000000000080000000000000000000000 *0000000001000000000000000900000000000000000000000000000001000000000000000a0000 *0000000000000000000000000001000000000000000b0000000000000000000000000000000100 *0000000000000c00000000000000000000000000000001000000000000000d0000000000000000 *0000000000000001010000000000000000000000000000000100000000000e0000000000000000 *000000000000000100000000000000020000000000000003000000000000000400000000000000 *050000000000000006000000000000000700000000000000080000000000000009000000000000 *000a000000000000000b000000000000000c000000000000000d0e000000000000000b00000000 *0000000c000000000000000d00000000000000080000000000000009000000000000000a000000 *000000000500000000000000060000000000000007000000000000000000000000000000010000 *00000000000200000000000000030000000000000004000000000000000e000000000000000000 *000000000000010300000000000000020000000000000000000000000000000103000000000000 *000300000000000000000000000000000001030000000000000004000000000000000000000000 *000000010000000000000000050000000000000000000000000000000100000000000000000600 *000000000000000000000000000001030000000000000007000000000000000000000000000000 *010100000000000000070000000000000000000000000000000100000000000000000800000000 *000000000000000000000001030000000000000009000000000000000000000000000000010100 *000000000000090000000000000000000000000000000100000000000000000a00000000000000 *00000000000000000103000000000000000b000000000000000000000000000000010100000000 *0000000b0000000000000000000000000000000100000000000000000c000000000000000d0000 *00000000000f6d6f6e61642d72616e2d302e302e360000000000000011436f6e74726f6c2e4d6f *6e61642e52616e0000000000000006524d6f6e6164000000000000000147000000000000000148 *0000000000000005746f52616e000000000000000766726f6d52616e000000000000000352616e *000000000000000667657452616e0000000000000009436f64656e73697479000000000000000c *676574436f64656e736974790000000000000006596f6e6564610000000000000009676574596f *6e656461 addfile ./doc/html/monad-ran/plus.gif binary ./doc/html/monad-ran/plus.gif oldhex * newhex *47494638396109000900910000fefefe8282820202020000002c00000000090009000002148c8f *a00bb6b29c82ca897b5b7871cfce74085200003b adddir ./doc/html/monad-ran/src addfile ./doc/html/monad-ran/src/Control-Monad-Ran.html hunk ./doc/html/monad-ran/src/Control-Monad-Ran.html 1 + + + + +Control/Monad/Ran.hs + + + +
-- Finding the right Kan extension
+
+module Control.Monad.Ran 
+    ( Yoneda(..)
+    , Codensity(..)
+    , Ran(..)
+    , RMonad
+    , G
+    , H
+    , toRan
+    , fromRan
+    ) where
+
+import Data.Monoid
+import Control.Applicative
+import Control.Monad
+import Control.Monad.Identity
+import Control.Monad.Cont
+import Control.Monad.State
+import Control.Monad.Error
+import Control.Monad.Reader
+import Control.Monad.Writer
+import Control.Monad.RWS
+
+data Yoneda f a = Yoneda { getYoneda :: forall b. (a -> b) -> f b } 
+
+instance Functor (Yoneda f) where
+    fmap f m = Yoneda (\k -> getYoneda m (k . f))
+
+instance Applicative f => Applicative (Yoneda f) where
+    pure a = Yoneda (\f -> pure (f a))
+    m <*> n = Yoneda (\f -> getYoneda m (f .) <*> getYoneda n id)
+
+instance Monad f => Monad (Yoneda f) where
+    return a = Yoneda (\f -> return (f a))
+    m >>= k = Yoneda (\f -> getYoneda m id >>= \a -> getYoneda (k a) f)
+
+instance MonadTrans Yoneda where
+    lift m = Yoneda (\f -> liftM f m)
+
+data Codensity f a = Codensity { getCodensity :: forall b. (a -> f b) -> f b }
+
+instance Functor (Codensity k) where
+    fmap f m = Codensity (\k -> getCodensity m (k . f))
+
+instance Applicative (Codensity f) where
+    pure = return
+    (<*>) = ap
+
+instance Monad (Codensity f) where
+    return x = Codensity (\k -> k x)
+    m >>= k = Codensity (\c -> getCodensity m (\a -> getCodensity (k a) c))
+
+instance MonadTrans Codensity where
+    lift m = Codensity (m >>=)
+
+runCodensity :: Monad m => Codensity m a -> m a
+runCodensity = flip getCodensity return
+
+runCodensityApp :: Applicative f => Codensity f a -> f a
+runCodensityApp = flip getCodensity pure
+
+-- .. Pointed
+
+data Ran m a = Ran { getRan :: forall b. (a -> G m b) -> H m b } 
+
+class Monad f => RMonad f where
+    type G f    :: * -> *
+    type H f    :: * -> *
+    toRan      :: f a -> Ran f a
+    fromRan    :: Ran f a -> f a
+
+--class RMonadTrans t where
+--    liftR :: RMonad m => RanT m a -> RanT (t m) a
+
+-- utility bifunctors for definitions below
+type Hom = (->)
+type (:->) = ReaderT
+
+data ErrorH b r  = ErrorH { getErrorH :: (b -> r) -> r } 
+data ErrorTH b m r = ErrorTH { getErrorTH :: (b -> G m r) -> H m r }
+
+-- Yoneda Identity
+-- forall o. (a -> o) -> o
+instance RMonad Identity where
+    type G Identity = Identity
+    type H Identity = Identity
+    toRan m = Ran (m >>=)
+    fromRan = flip getRan Identity
+
+-- Yoneda Endo
+-- forall o. (a -> o) -> o -> o
+instance RMonad Maybe where
+    type G Maybe = Identity
+    type H Maybe = Endo
+    toRan (Just x) = Ran (\k -> Endo (\_ -> runIdentity (k x)))
+    toRan Nothing = Ran (\_ -> Endo id)
+    fromRan (Ran f) = appEndo (f (Identity . Just)) Nothing
+
+-- Yoneda (ErrorH b)
+-- forall o. (a -> o) -> (b -> o) -> o
+instance Error b => RMonad (Either b) where
+    type G (Either b) = Identity
+    type H (Either b) = ErrorH b
+
+-- Yoneda (ErrorTH b m)
+-- forall o. (a -> G m o) -> (b -> G m o) -> H m o
+instance (RMonad m, Error b) => RMonad (ErrorT b m) where
+   type G (ErrorT b m) = G m 
+   type H (ErrorT b m) = ErrorTH b m
+
+-- Yoneda f
+-- forall o. (a -> o) -> f o 
+instance Monad f => RMonad (Yoneda f) where
+    type G (Yoneda f) = Identity
+    type H (Yoneda f) = f
+
+-- Codensity f
+-- forall o. (a -> f o) -> f o 
+instance RMonad (Codensity f) where
+    type G (Codensity f) = f
+    type H (Codensity f) = f
+
+-- Yoneda (Reader r)
+-- forall o. (a -> o) -> r -> o
+instance RMonad (Reader e) where
+    type G (Reader e) = Identity
+    type H (Reader e) = Hom e
+
+-- embedded as CPS'd State to avoid superfluous 'mappend mempty' calls
+-- specialized Codensity (Reader w)
+-- forall o. (a -> w -> o) -> w -> o
+instance Monoid w => RMonad (Writer w) where
+    type G (Writer w) = Hom w
+    type H (Writer w) = Hom w
+    -- forall o. (a -> w -> o) -> o
+    -- type H (Writer w) = Identity
+
+-- Codensity (Reader s)
+-- forall o. (a -> s -> o) -> s -> o
+instance RMonad (State s) where
+    type G (State s) = Hom s
+    type H (State s) = Hom s
+
+-- Codensity (Const r)
+-- (a -> r) -> r
+instance RMonad (Cont r) where
+    type G (Cont r) = Const r
+    type H (Cont r) = Const r
+
+-- forall o. (a -> G m o) -> r -> H m o 
+instance RMonad m => RMonad (ReaderT e m) where
+    type G (ReaderT e m) = G m
+    type H (ReaderT e m) = e :-> H m
+
+-- forall o. (a -> w -> G m o) -> H m o
+instance (Monoid w, RMonad m) => RMonad (WriterT w m) where
+    type G (WriterT w m) = w :-> G m
+    type H (WriterT w m) = H m
+
+-- forall o. (a -> s -> G m o) -> s -> H m o 
+instance RMonad m => RMonad (StateT s m) where
+    type G (StateT s m) = s :-> G m
+    type H (StateT s m) = s :-> H m
+
+-- (a -> G m r) -> H m r
+data ConstT r f a = ConstT { getConstT :: f r } 
+instance RMonad m => RMonad (ContT r m) where
+    type G (ContT r m) = ConstT r (G m)
+    type H (ContT r m) = ConstT r (H m)
+
+ addfile ./doc/html/monad-ran/src/hscolour.css hunk ./doc/html/monad-ran/src/hscolour.css 1 +.hs-keyglyph, .hs-layout {color: red;} +.hs-keyword {color: blue;} +.hs-comment, .hs-comment a {color: green;} +.hs-str, .hs-chr {color: teal;} +.hs-keyword, .hs-conid, .hs-varid, .hs-conop, .hs-varop, .hs-num, .hs-cpp, .hs-sel, .hs-definition {} }