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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:34:52+00:00 2026-06-10T01:34:52+00:00

just looking for an explanation how does following composition work: (=<<) . return where

  • 0

just looking for an explanation how does following composition work:

(=<<) . return

where

(=<<) ::       (a -> m b) -> m a -> m b
return :: a -> m a
(.) :: (b -> c) -> (a -> b) -> a -> c

The final type:

GHCi> :t (=<<) . return
(=<<) . return :: Monad m => m b -> m a -> m b

I cann’t grasp how can match m a with (a -> m b) , ie. how can apply result of return which is a simple type to first argument of (=<<) expecting a function type ?

  • 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-10T01:34:53+00:00Added an answer on June 10, 2026 at 1:34 am

    The explanation is:

    1. Your return is (perhaps unexpectedly) of a different monad than your =<<.
    2. The monad it uses is the reader monad (->) r.

    The compiler tries to unify the result of return :: c -> m' c with the first argument of (a -> m b) -> m a -> m b, so to unify m' c with a -> m b. The only possibility is that m' is the reader monad (->) r for some r. Next, it tries to unify (->) r c with (converted to the prefix notation) (->) a (m b), which is solved by setting r to a and c to m b. So, after unification, the compiler gets the most general possible type

    return :: (m b) -> ((->) a (m b))
    

    or in the usual infix notation

    return :: (m b) -> (a -> m b)
    

    See also:

    • How to use (->) instances of Monad and confusion about (->)
    • The source where the instance of Monad ((->) r) is defined.

    Edit: To define a monad, we need a (partially applied) type of kind * -> *. These are almost always partially applied data constructors, but this particular case, we view -> as a type operator that takes 2 type arguments and creates a new type (the function type). So for any given type r, the partially applied expression (->) r is a type of kind * -> *. As it turns out, there is a straightforward way how to describe monad operations on it. See Control.Reader monad and also this article that explains it. The monad operations for Reader are implemented exactly the same way as for (->), the only difference is that Reader wraps the operations into a distinct data type.

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

Sidebar

Related Questions

Just looking on resources that break down how frames per second work. I know
Basically just looking to see if you can capture an image from the webcam
I was just looking at this code and i don't understand what RETURN TRUE
I'm looking for a good article or two, or just an explanation, on how
I'm just looking for a simple, concise explanation of the difference between these two.
I've been looking around a bit and can't seem to find just what Im
Just looking for a good PHP Image Library, I want to display images with
I just looking how to use LINQ for grouping a list. Class Item Public
I was just looking at this example from Deitel : #include <stdio.h> struct card
I was just looking at the MySql database created by drupal after I installed

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.