Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:34:39+00:00 2026-05-29T05:34:39+00:00

Monads are known to be theoretically a subset of functors and specifically applicative functors,

  • 0

Monads are known to be theoretically a subset of functors and specifically applicative functors, even though it’s not indicated in Haskell’s type system.

Knowing that, given a monad and basing on return and bind, how to:

  • derive fmap,
  • derive <*> ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:34:40+00:00Added an answer on May 29, 2026 at 5:34 am

    Well, fmap is just (a -> b) -> f a -> f b, i.e. we want to transform the monadic action’s result with a pure function. That’s easy to write with do notation:

    fmap f m = do
      a <- m
      return (f a)
    

    or, written “raw”:

    fmap f m = m >>= \a -> return (f a)
    

    This is available as Control.Monad.liftM.

    pure :: a -> f a is of course return. (<*>) :: f (a -> b) -> f a -> f b is a little trickier. We have an action returning a function, and an action returning its argument, and we want an action returning its result. In do notation again:

    mf <*> mx = do
      f <- mf
      x <- mx
      return (f x)
    

    Or, desugared:

    mf <*> mx =
      mf >>= \f ->
      mx >>= \x ->
      return (f x)
    

    Tada! This is available as Control.Monad.ap, so we can give a complete instance of Functor and Applicative for any monad M as follows:

    instance Functor M where
      fmap = liftM
    
    instance Applicative M where
      pure = return
      (<*>) = ap
    

    Ideally, we’d be able to specify these implementations directly in Monad, to relieve the burden of defining separate instances for every monad, such as with this proposal. If that happens, there’ll be no real obstacle to making Applicative a superclass of Monad, as it’ll ensure it doesn’t break any existing code. On the other hand, this means that the boilerplate involved in defining Functor and Applicative instances for a given Monad is minimal, so it’s easy to be a “good citizen” (and such instances should be defined for any monad).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is well-known that applicative functors are closed under composition but monads are not.
I'm reading the Monads chapter in Real World Haskell (chapter 14). A function is
While monads are represented in Haskell using the bind and return functions, they can
Okay, so I am not a Haskell programmer, but I am absolutely intrigued by
I am trying to do a global counter using monads in Haskell, I want
Two well-known examples of applicatives are monads and ziplists. Are there any other examples?
I'm a Haskell beginner, I'm just beginning to wrap my head around Monads, but
I am now struggling with Haskell. Even, I have some experience with imperative languages,
While learning Haskell I had the feeling that the authors where not always telling
When reading up on type classes I have seen that the relationship between Functors,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.