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

  • Home
  • SEARCH
  • 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 222485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:07:54+00:00 2026-05-11T19:07:54+00:00

I was trying to implement the function every :: (a -> IO Bool) ->

  • 0

I was trying to implement the function

every :: (a -> IO Bool) -> [a] -> IO Bool 

which was the topic for this question. I tried to do this without explicit recursion. I came up with the following code

every f xs = liftM (all id) $ sequence $ map f xs

My function didn’t work since it wasn’t lazy (which was required in the question), so no upvotes there :-).

However, I did not stop there. I tried to make the function point-free so that it would be shorter (and perhaps even cooler). Since the arguments f and xs are the last ones in the expression I just dropped them:

every = liftM (all id) $ sequence $ map 

But this did not work as expected, in fact it didn’t work at all:

    [1 of 1] Compiling Main             ( stk.hs, interpreted )

    stk.hs:53:42:
        Couldn't match expected type `[m a]'
               against inferred type `(a1 -> b) -> [a1] -> [b]'
        In the second argument of `($)', namely `map'
        In the second argument of `($)', namely `sequence $ map'
        In the expression: liftM (all id) $ sequence $ map
    Failed, modules loaded: none.

Why is that? I was under the impression that it was possible to simply drop trailing function arguments, which basically is what currying is about.

  • 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-11T19:07:54+00:00Added an answer on May 11, 2026 at 7:07 pm

    The definition of $ is

    f $ x = f x
    

    Let’s fully parenthesize your function:

    every f xs = (liftM (all id)) (sequence ((map f) xs))
    

    and your curried version:

    every = (liftM (all id)) (sequence map)
    

    As you noticed, these are not identical. You can only drop trailing function arguments when they are the last thing applied. For example,

    f x = g c x
    

    is actually

    f x = (g c) x
    

    and the application of (g c) to x comes last, so you can write

    f = g c
    

    One pattern with the application operator $ is that it often becomes the composition operator . in points-free versions. This is because

    f $ g $ x
    

    is equivalent to

    (f . g) $ x
    

    For example,

    every f xs = liftM (all id) $ sequence $ map f xs
    

    can become

    every f xs = (liftM (all id) . sequence . map f) xs
    

    at which point you can drop xs:

    every f = liftM (all id) . sequence . map f
    

    Eliminating the argument f is more difficult, because it is applied before the composition operator. Let’s use the definition of dot from http://www.haskell.org/haskellwiki/Pointfree:

    dot = ((.) . (.))
    

    With points, this is

    (f `dot` g) x = f . g x
    

    and is exactly what we need to make every fully points-free:

    every = (liftM (all id) . sequence) `dot` map
    

    Sadly, due to restrictions in the Haskell type system, this one needs an explicit type signature:

    every :: (Monad m) => (a -> m Bool) -> [a] -> m Bool
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 211k
  • Answers 211k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In the example config file for HttpCompress they give two… May 12, 2026 at 10:10 pm
  • Editorial Team
    Editorial Team added an answer When you use singleton scope from the Spring container, you… May 12, 2026 at 10:10 pm
  • Editorial Team
    Editorial Team added an answer A Windows machine can easily scale to very high numbers… May 12, 2026 at 10:10 pm

Related Questions

In many embedded applications there is a tradeoff between making the code very efficient
I have a pointer to a given class. Lets say, for example, the pointer
I have a large database of users (~200,000) that I'm transferring from a ASP.NET
I'm trying to implement an IErrorHandler in my WCF service in order to log

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.