[Haskell-beginners] Trivial function of type (a -> b) -> Maybe a -> Maybe b

Eugen Zagorodniy e.zagorodniy at gmail.com
Wed Jan 13 10:01:13 EST 2010


Wed, 13 Jan 2010 08:47:42 -0600 Antoine Latter:
> On Wed, Jan 13, 2010 at 8:44 AM, Eugen Zagorodniy
> <e.zagorodniy at gmail.com> wrote:
> > Greetings!
> >
> > I looked at documentation of Maybe type and suprisingly found no
> > function like
> >
> > maybize             :: (a -> b) -> Maybe a -> Maybe b
> > maybize f Nothing   =  Nothing
> > maybize f (Just x)  =  Just (f x)
> >
> 
> Have you looked at:
> 
> fmap :: Functor f => (a -> b) -> f a -> f b
> 
> It will do what you want, and has the bonus of doing the same
> operation for a lot more structures.

Sure that is it. I should pay more attention to standard type classes.

Thanks!


More information about the Beginners mailing list