Jonathan,
On Mon, 2008-11-24 at 14:06 -0800, Greg Meredith wrote:It might be pointed out that List and Set are also in this region. In
> Haskellians,
> Some monads come with take-out options, e.g.
> * List
> * Set
> In the sense that if unit : A -> List A is given by unit a = [a], then
> taking the head of a list can be used to retrieve values from inside
> the monad.
> Some monads do not come with take-out options, IO being a notorious
> example.
> Some monads, like Maybe, sit on the fence about take-out. They'll
> provide it when it's available.
fact, Maybe is better, in this regard, since you know, if fromJust
succeeds, that it will only have once value to return. head might find
one value to return, no values, or even multiple values.
A better example of a monad that always has a left inverse to return is
((,) w), where w is a monoid. In this case,
snd . return = id :: a -> a
as desired (we always have the left inverses
join . return = id :: m a -> m a
where join a = a >>= id).
Sounds reasonable. Foldable gives you something:
> Now, are there references for a theory of monads and take-out options?
> For example, it seems that all sensible notions of containers have
> take-out.
foldr const undefined
will pull out the last value visited by foldr, and agrees with head at [].
If you want. I'd rather define a container to be Traversable; it
> Can we make the leap and define a container as a monad with a notion
> of take-out?
doesn't exclude anything interesting (that I'm aware of), and is mostly
more powerful.
> Has this been done?
Are you familiar at all with Foldable
(http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Foldable.html#t%3AFoldable) and Traversable (http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Traversable.html#t%3ATraversable)
jcc