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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:29:08+00:00 2026-05-18T09:29:08+00:00

From time to time I stumble over the problem that I want to express

  • 0

From time to time I stumble over the problem that I want to express “please use the last argument twice”, e.g. in order to write pointfree style or to avoid a lambda. E.g.

sqr x = x * x

could be written as

sqr = doubleArgs (*) where
   doubleArgs f x = f x x

Or consider this slightly more complicated function (taken from this question):

ins x xs = zipWith (\ a b -> a ++ (x:b)) (inits xs) (tails xs)

I could write this code pointfree if there were a function like this:

ins x = dup (zipWith (\ a b -> a ++ (x:b))) inits tails where
     dup f f1 f2 x = f (f1 x) (f2 x)

But as I can’t find something like doubleArgs or dup in Hoogle, so I guess that I might miss a trick or idiom here.

  • 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-18T09:29:09+00:00Added an answer on May 18, 2026 at 9:29 am

    From Control.Monad:

    join :: (Monad m) -> m (m a) -> m a
    join m = m >>= id
    
    instance Monad ((->) r) where
        return = const
        m >>= f = \x -> f (m x) x
    

    Expanding:

    join :: (a -> a -> b) -> (a -> b)
    join f = f >>= id
           = \x -> id (f x) x
           = \x -> f x x
    

    So, yeah, Control.Monad.join.

    Oh, and for your pointfree example, have you tried using applicative notation (from Control.Applicative):

    ins x = zipWith (\a b -> a ++ (x:b)) <$> inits <*> tails
    

    (I also don’t know why people are so fond of a ++ (x:b) instead of a ++ [x] ++ b… it’s not faster — the inliner will take care of it — and the latter is so much more symmetrical! Oh well)

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

Sidebar

Related Questions

From time to time I read that Fortran is or can be faster then
From time to time, a file that I'm interested in is modified by some
I see this from time to time and want to know what it is.
From time to time I see an enum like the following: [Flags] public enum
From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread.
From time to time I browse the web and look for interesting algorithms and
From time to time, I need to dump USB traffic under Windows, mostly to
From time to time, I run into communications issue with other programmers, when we
From time to time my applications GUI stops redrawing. There a lot of threads
I make a lot of web applications and from time to time I need

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.