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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:46:11+00:00 2026-06-13T11:46:11+00:00

I am having difficulty understanding how a function can be a monad. Function (->)

  • 0

I am having difficulty understanding how a function can be a monad.

Function (->) r is a monad according to a declaration in Control.Monad.Instances:

instance Monad ((->) r) where  
    return x = \_ -> x  
    h >>= f = \w -> f (h w) w  

Even what Miran Lipovača says about it makes me confused:

The implementation for >>= seems a bit cryptic, but it’s really not
all that. When we use >>= to feed a monadic value to a function, the
result is always a monadic value. So in this case, when we feed a
function to another function, the result is a function as well. That’s
why the result starts off as a lambda. All of the implementations of
>>= so far always somehow isolated the result from the monadic value and then applied the function f to that result. The same thing happens
here. To get the result from a function, we have to apply it to
something, which is why we do (h w) here to get the result from the
function and then we apply f to that. f returns a monadic value, which
is a function in our case, so we apply it to w as well.

The type signature of (>>=) is this:
(>>=) :: m a -> (a -> m b) -> m b

So I take that h is typed as m a and f as (a -> m b). If a function is m a, does it return an a type value? or does it return something else taking an a type?

If the non-monad value of h is fed to f, then we get:
f (h w)
Looks fine. Since f is a function and has taken its sole argument, it is already a value, no? Since it’s a monadic function the value is also a monadic value. Why then does it need another value w? Doesn’t feeding w to f something make it non-monadic, i.e., it is not a function any more, no? I also cannot understand why f something and h take the same argument w and return different value types (m a and m b).

  • 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-13T11:46:12+00:00Added an answer on June 13, 2026 at 11:46 am

    First, here’s the type of (>>=):

    (>>=) :: (Monad m) => m a -> (a -> m b) -> m b
    

    Now, with m specialized to ((->) r):

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

    Rewritten with all the function arrows infix:

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

    Removing some superfluous parentheses:

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

    At which point it should be much easier to see what’s going on: the third argument (of type r) is given to the first argument to get something of type a, then both that result and the third argument are given to the second argument to get a final result of type b.

    So, ((->) r) as a Monad represents an extra function argument to every value in that monad, and when monadic values are combined the single “extra” argument is duplicated and given to each input value. Essentially, this creates a “read-only global environment” for monadic values. This interpretation is provided explicitly as the Reader monad, which is just a wrapper around ((->) r).

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

Sidebar

Related Questions

I'm having a bit of difficulty understanding how the python __init__ ( ) function
I'm having difficulty understanding how 'static' stuff works in PHP. Can someone point me
Hi everyone I'm having difficulty understanding the following function structures. Could somebody walk me
I'm having difficulty understanding variable shadowing in JavaScript based on scopes. Consider this small
I am having difficulty understanding the part value : value == 0 ? How
So I am new to C# and I am having difficulty understanding out .
So I'm new to regular expressions and having difficulty understanding them. To get my
I was going through an interview question on JavaRevisited and I'm having difficulty understanding
I am new to programming and am having difficulty with understanding object lifetime /
I'm working on an ASP.NET application and I'm having difficulty in understanding why a

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.