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 8599529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:25:03+00:00 2026-06-12T01:25:03+00:00

Give a definition of the function fmap :: (a->b) -> IO a -> IO

  • 0

Give a definition of the function
fmap :: (a->b) -> IO a -> IO b

the effect of which is to transform an interaction by applying the function to its result. you should define it using the do construct.

how should I define the fmap? I have no idea about it?

could someone help me with that?

Thanks~!

  • 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-06-12T01:25:04+00:00Added an answer on June 12, 2026 at 1:25 am

    It looks like homework or something so I will give you enough hint so that you can work rest of the details yourself.

    fmap1 :: (a -> b) -> IO a -> IO b 
    fmap1 f action = 
    

    action is as IO action and f is a function from a to b and hence type a -> b.

    If you are familiar with monadic bind >>= which has type (simplified for IO monad)

    (>>=) :: IO a -> (a -> IO b) -> IO b
    

    Now if you look at

    action >>= f
    

    It means perform the IO action which returns an output (say out of type a) and pass the output to f which is of type a -> IO b and hence f out is of type IO b.

    If you look at the second function called return which has type (again simlified for IO monad)

    return :: a -> IO a
    

    It takes a pure value of type a and gives an IO action of type IO a.

    Now lets look back to fmap.

    fmap1 f action 
    

    which performs the IO action and then runs f on the output of the action and then converts the output to another IO action of type IO b. Therefore

    fmap1 f action = action >>= g 
        where
            g out = return (f out)
    

    Now comes the syntactic sugar of do notation. Which is just to write bind >>= in another way.

    In do notation you can get the output of an action by

    out <- action 
    

    So bind just reduces to

    action >>= f = do 
        out <- action 
        f out 
    

    I think now you will be able to convert the definition of fmap to do construct.

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

Sidebar

Related Questions

Is it appropriate to give the Definition of a small Function -- which is
Do anyone can give example of function composition? This is the definition of function
When a friend function is included in the namespace, its definition needs to be
So I write a function with the definition getLastDigits :: String -> String which
I want to define a Perl function (call it difference) which depends on a
I just had a test on java and we had to give the definition
give me suggestion which is related to table view selection action. I have a
Please give me some tips for this case. I have an iPhone APP which
I'm trying to write the Haskell function 'splitEvery' in Python. Here is it's definition:
I have a situaion in which I want to declare a class member function

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.