1 Sep 2006 01:13
Re: A free monad theorem?
Benjamin Franksen <benjamin.franksen <at> bessy.de>
2006-08-31 23:13:14 GMT
2006-08-31 23:13:14 GMT
Tomasz Zielonka wrote: > On Thu, Aug 31, 2006 at 07:23:55PM +0200, Benjamin Franksen wrote: >> I'd like to know if the following reasoning can be made more precise: >> >> As we all know, the monadic bind operation has type: >> >> bind :: Monad m => m a -> (a -> m b) -> m b >> >> My intuition says that in order to apply the second argument to some >> non-trivial (i.e. non-bottom) value of type a, the bind operator needs to >> be able to somehow 'extract' a value (of type a) from the first argument >> (of type m a). > > The bind operator doesn't have to neccesarily apply the second argument > to anything. What if m is Maybe, and the first arguments is Nothing? True, however if the instance for Maybe would have been defined without /ever/ applying the second argument to anything, then wouldn't this necessarily be a trivial monad (however one would need to define 'trivial' here)? > And if the bind operator "wants" to apply the second argument to > something, it doesn't have to do it only once - consider the [] monad. Yes, I should have said: Any non-trivial definition of bind has to apply its second argument at least in _some_ cases and _at least_ once to something non-bottom. > Other examples: >(Continue reading)
But now I know that you are not really claiming such a function exists.
> The real question (the one that bugs me, anyway) is if one can give a
> precise meaning to the informal argument that if the definition of bind is
> to be non-trivial then its second argument must be applied to some
> non-trivial value at one point (but not, of course, in all cases, nor
> necessarily only once)
How about using monad laws, specifically:
(return x) >>= f == f x
We assume that >>= never uses it's second argument, so:
(return x) >>= f == (return x) >>= g
Combining it with the above monad law we get:
f x == (return x) >>= f == (return x) >>= g == g x
so
f x = g x
It seems I am not getting
something.
RSS Feed