[Haskell-cafe] example in "All about Monads"

wren ng thornton wren at freegeek.org
Fri Sep 17 23:26:39 EDT 2010

On 9/17/10 12:48 PM, ender wrote:
> my question is, why not define the function father and mother as type of
> father::Maybe Sheep ->  Maybe Sheep? this can also
> clean the code and it avoid the additional function comb

Do note that `comb` is giving you a natural way of creating those functions:

     flip comb :: (a -> Maybe a) -> (Maybe a -> Maybe a)

Since we can define comb, every (a -> Maybe a) has an associated 
function of type (Maybe a -> Maybe a). And if we use comb, then that 
means we can use the function at either type, just pick whichever one is 
easier for us to use at the time. If we only ever defined (Maybe a -> 
Maybe a) functions then we'd need to use a combinator to go the other way...

     f :: a -> Maybe a
     g :: Maybe a -> Maybe a

     f = ...
     g = flip comb f

     -- or --

     f = g . Just
     g = ...

Whether we use (flip comb) or (. Just) doesn't really matter too much. 
The point is that we can go both ways.

Live well,

More information about the Haskell-Cafe mailing list