Can please someone explain the differences between Functor and Monad in the Scala context?
Can please someone explain the differences between Functor and Monad in the Scala context?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Scala itself really does not emphasize the
FunctorandMonadterms that much. I guess usingmapis the functor side, usingflatMapis the Monad side.For me looking and playing around with scalaz has been so far the best avenue to get a sense of those functional concepts in the scala context (versus the haskell context). Two years ago when I started scala, the scalaz code was gibberish to me, then a few months ago I started looking again and I realized that it’s really a clean implementation of that particular style of functional programming.
For instance the
Monadimplementation shows that a monad is a pointed functor because it extends thePointedtrait (as well as theApplicativetrait). I invite you to go look at the code. It has linking in the source itself and it’s really easy to follow the links.So functors are more general. Monads provide additional features. To get a sense of what you can do when you have a functor or when you have a monad, you can look at
MAYou’ll see utility methods that need an implicit functor (in particular applicative functors) such as
sequenceand sometime methods that needs a full monad such asreplicateM.