
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) I believe there should be a good reason for absence of such function, say: 1) there is an idiomatic way (probably utilizing higher level abstractions) of doing the same what 'maybize' does, 2) no one really needs it... except me, 3) ?.. Did I miss something? (It is rather about curiosity than a real problem though). Thanks in advance for any comments!

On Wed, Jan 13, 2010 at 8:44 AM, Eugen Zagorodniy
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. Antoine http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/Prelude.html#...

Wed, 13 Jan 2010 08:47:42 -0600 Antoine Latter:
On Wed, Jan 13, 2010 at 8:44 AM, Eugen Zagorodniy
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!

Sure that is it. I should pay more attention to standard type classes.
Typeclassopedia will help you to understand these type classes:
http://www.haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf
-- nwn
On Thu, Jan 14, 2010 at 12:01 AM, Eugen Zagorodniy
Wed, 13 Jan 2010 08:47:42 -0600 Antoine Latter:
On Wed, Jan 13, 2010 at 8:44 AM, Eugen Zagorodniy
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! _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

"Eugen" == Eugen Zagorodniy
writes:
Eugen> Greetings! I looked at documentation of Maybe type and Eugen> suprisingly found no function like Eugen> maybize :: (a -> b) -> Maybe a -> Maybe b maybize f Nothing Eugen> = Nothing maybize f (Just x) = Just (f x) Isn't that fmap? -- Colin Adams Preston Lancashire
participants (4)
-
Antoine Latter
-
Colin Paul Adams
-
Eugen Zagorodniy
-
Yusaku Hashimoto