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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:06:41+00:00 2026-05-20T18:06:41+00:00

At different questions I’ve found hints in comments concerning using the (->) instance of

  • 0

At different questions I’ve found hints in comments concerning using the (->) instance of Monads e.g. for realizing point-free style.

As for me, this is a little too abstract. Ok, I’ve seen Arrow instances on (->) and it seems to me, that (->) can be used in instance notations but not in type declarations (that would alone be stuff for another question).

Has anyone examples using (->) as instance of Monad? Or a good link?

Sorry if this question may already have been discussed here, but searching for “(->) Monad instance” gives you many many hits as you can imagine … since nearly every question about Haskell somewhere involves (->) or “Monad”.

  • 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-20T18:06:41+00:00Added an answer on May 20, 2026 at 6:06 pm

    For a given type r, the function of type r -> a can be thought of as a computation delivering an a using an environment typed r. Given two functions r -> a and a -> (r -> b), it’s easy to imagine that one can compose these when given an environment (again, of type r).

    But wait! That’s exactly what monads are about!

    So we can create an instance of Monad for (->) r that implements f >>= g by passing the r to both f and g. This is what the Monad instance for (->) r does.

    To actually access the environment, you can use id :: r -> r, which you can now think of as a computation running in an environment r and delivering an r. To create local sub-environments, you can use the following:

    inLocalEnvironment :: (r -> r) -> (r -> a) -> (r -> a)
    inLocalEnvironment xform f = \env -> f (xform env)
    

    This pattern of having an environment passed to computations that can then query it and modify it locally is useful for not just the (->) r monad, which is why it is abstracted into the MonadReader class, using much more sensible names than what I’ve used here:

    http://hackage.haskell.org/packages/archive/mtl/2.0.1.0/doc/html/Control-Monad-Reader-Class.html

    Basically, it has two instances: (->) r that we’ve seen here, and ReaderT r m, which is just a newtype wrapper around r -> m a, so it’s the same thing as the (->) r monad I’ve described here, except it delivers computations in some other, transformed monad.

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

Sidebar

Related Questions

This questions involves 2 different implementations of essentially the same code. First, using delegate
Here are two different questions but I think they are related. When using Git,
I have seen different questions regarding this, but I still find this topic to
This is a little different than the questions that have already been asked on
I've posted some questions on this before, but it's different. So consider a small
this is a different question concerning: add a connection to database not working, asp.net
This is similar to one of my other questions, but different enough I think
I've found a number of different questions on generating UIDs, but as far as
I know, there are many different questions and so many answers about this problem...
I've got quiz application. Where robot ask different questions in chat, this questions belong

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.