[Haskell-cafe] FW: RE Monad Description For Imperative Programmer

Kim-Ee Yeoh a.biurvOir4 at asuhan.com
Wed Aug 8 09:32:58 EDT 2007



Claus Reinke wrote:
> 
> there is usually a way to interpret monadic structures built in
> this way (a 'run' operation of some kind).
> 

The "run" operation of type (m a -> a) is the (comonadic) coreturn. Many
monads are almost comonads too, for a meaning of "almost" to be made
precise.


Claus Reinke wrote:
> 
>     - i/o: primitive monadic things are basic i/o operations, 
>         the 'run' operation is outside the language, applied to
>         'Main.main', and interprets (abstract) IO monad structures
>         sequentially, starting with the leftmost innermost i/o 
>         operation in the structure and applying the second
>         argument of (>>=) to the result of executing the first.
> 

"Run" for IO monad is obviously unsafePerformIO :: IO a -> a.


Claus Reinke wrote:
> 
>     - []: primitive monadic things are lists, the 'run' operation
>         is the identity, ie, the lists are directly exposed as data
>         structures, return creates a singleton list, (>>=) applies
>         its second argument to each element of its first argument
>         and concatenates the results (concatMap).
> 

"Run" for [] is almost head :: [a] -> a. For the type of infinite streams,
the research community's comonad de rigeur, coreturn _is_ h(ea)d.


Claus Reinke wrote:
> 
>     - State: primitive monadic things are operations on a state
>         type, returning a result and a state; return returns its 
>         parameter, passing its input state unchanged, (>>=) applies 
>         its first parameter to the input state, applies its second 
>         parameter to the result value and result state of the first. 
>         'run' is runState and applies a (possibly) complex monadic 
>         thing to an input state, returning a result and a (modified) 
>         state.
> 

The State monad is almost (there's that word again!) like the Context
comonad. And the Context comonad is a comonadification of the suboptimally
named Reader monad, a comonadification that wants to be made precise.

In fact, there's another comonad that solves the analogical equation:
comonad x is to monad State as comonad Context is to monad Reader. Any
takers on calling x the Costate comonad and Reader the Ntext monad?

-- 
View this message in context: http://www.nabble.com/FW%3A-RE-Monad-Description-For-Imperative-Programmer-tf4200420.html#a12053227
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list