# Adding 1 to Just 9

4 messages
Open this post in threaded view
|

## Adding 1 to Just 9

 Dear List, Chapter 14 of LYH appears to suggest that a Just value can be added to an Int. Quote from http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions"For instance, say we have Just 9 and the function \x -> Just (x+1). If we map this function over Just 9, we're left with Just (Just 10)." I've tried the following in ghci but got the error: :12:1: error:      • Non type-variable argument in the constraint: Num (Maybe a)        (Use FlexibleContexts to permit this)      • When checking the inferred type          it :: forall a. (Num (Maybe a), Num a) => Maybe a Am I reading the quote wrong? Is Just (Just 10) a hypothetical? Regards, - Olumide _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: Adding 1 to Just 9

 let foo = \x -> Just (x + 1)fmap foo (Just 9)Just (Just 10)On Mon, May 14, 2018 at 8:15 AM, Olumide wrote:Dear List, Chapter 14 of LYH appears to suggest that a Just value can be added to an Int. Quote from http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions "For instance, say we have Just 9 and the function \x -> Just (x+1). If we map this function over Just 9, we're left with Just (Just 10)." I've tried the following in ghci but got the error: :12:1: error:     • Non type-variable argument in the constraint: Num (Maybe a)       (Use FlexibleContexts to permit this)     • When checking the inferred type         it :: forall a. (Num (Maybe a), Num a) => Maybe a Am I reading the quote wrong? Is Just (Just 10) a hypothetical? Regards, - Olumide _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners