
25 Aug
2017
25 Aug
'17
8:27 a.m.
PICCA Frederic-Emmanuel wrote (2017-08-25 08:05:34):
Hello, I have this
data Proxy = Proxy String
And I want to write a function
f :: Maybe Proxy -> Maybe String f ma = case ma of (Just (Proxy a)) -> Just a Nothing -> Nothing
I was wondering if there is no simpler way to do this ?
Maybe implements the Functor type class (as an exercise, you can try to figure out the implementation), therefore you can simply use fmap, which in the case of Maybe, has type (a -> b) -> Maybe a -> Maybe b You just need a function to "unwrap" the String inside of the Proxy, and you're done. -- Olivier