[Haskell-cafe] A function for Maybes

2007-01-25 Thread John Ky
Is there a built-in function that already does this? foo :: (a - b) - Maybe a - Maybe b foo f m | isNothing m = Nothing | otherwise = Just (f (fromJust m)) *Main foo (+2) (Just 3) Just 5 *Main foo (+2) Nothing Nothing If so what is it? If not, what should I call it? Thanks -John

Re: [Haskell-cafe] A function for Maybes

2007-01-25 Thread Brandon S. Allbery KF8NH
On Jan 25, 2007, at 9:15 , John Ky wrote: Is there a built-in function that already does this? foo :: (a - b) - Maybe a - Maybe b foo f m | isNothing m = Nothing | otherwise = Just (f (fromJust m)) Nothing specific to Maybe, because the more general liftM (over monads) or fmap (over

Re: [Haskell-cafe] A function for Maybes

2007-01-25 Thread J. Garrett Morris
fmap. e.g.: Prelude fmap ('c':) (Just a) Just ca Prelude fmap ('c':) Nothing Nothing Prelude /g On 1/25/07, John Ky [EMAIL PROTECTED] wrote: Is there a built-in function that already does this? foo :: (a - b) - Maybe a - Maybe b foo f m | isNothing m = Nothing | otherwise = Just (f

Re: [Haskell-cafe] A function for Maybes

2007-01-25 Thread Andrew Wagner
:t liftM forall r (m :: * - *) a1. (Monad m) = (a1 - r) - m a1 - m r liftM (+2) (Just 3 Just 5 liftM (+2) Nothing Nothing (Thanks to allbery_b for contributing to the discussion on #haskell) On 1/25/07, John Ky [EMAIL PROTECTED] wrote: Is there a built-in function that already does this?

Re: [Haskell-cafe] A function for Maybes (RESOLVED)

2007-01-25 Thread John Ky
Thanks -John On 1/26/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: On Jan 25, 2007, at 9:15 , John Ky wrote: Is there a built-in function that already does this? foo :: (a - b) - Maybe a - Maybe b foo f m | isNothing m = Nothing | otherwise = Just (f (fromJust m)) Nothing