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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:57:46+00:00 2026-05-30T17:57:46+00:00

I was reading the answer to this question: Haskell: difference between . (dot) and

  • 0

I was reading the answer to this question: Haskell: difference between . (dot) and $ (dollar sign) And the reply struck me as odd… What does he mean + has no input? And then I tried:

((+) 1)
((+) 1 1)
((+) 1 1 1)

Whoops… sad news. But I’m sure I saw functions that can take seemingly arbitrary or a very large number of arguments to believe that someone had defined them in a way a->b->c…->z. There must be some way to handle it! What I’m looking for is something like &rest or &optional in CL.

  • 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-30T17:57:48+00:00Added an answer on May 30, 2026 at 5:57 pm

    Sure, you can define a variadic addition function, with some typeclass hackery:1

    {-# LANGUAGE TypeFamilies #-}
    
    class Add r where
        add' :: (Integer -> Integer) -> r
    
    instance Add Integer where
        add' k = k 0
    
    instance (n ~ Integer, Add r) => Add (n -> r) where
        add' k m = add' (\n -> k (m+n))
    
    add :: (Add r) => r
    add = add' id
    

    And so:

    GHCi> add 1 2 :: Integer
    3
    GHCi> add 1 2 3 :: Integer
    6
    

    The same trick is used by the standard Text.Printf module. It’s generally avoided for two reasons: one, the types it gives you can be awkward to work with, and you often have to specify an explicit type signature for your use; two, it’s really a hack, and should be used rarely, if at all. printf has to take any number of arguments and be polymorphic, so it can’t simply take a list list, but for addition, you could just use sum.

    1 The language extension isn’t strictly necessary here, but they make the usage easier (without them, you’d have to explicitly specify the type of each argument in the examples I gave, e.g. add (1 :: Integer) (2 :: Integer) :: Integer).

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

Sidebar

Related Questions

I have this question after reading the answer here , what's the difference at
Thanks in Advance for reading and answer this question. I got button in asp
After reading this question , i saw the answer by Naveen containing a link
I was reading over this question and wondered if the accepted answer might also
After reading the answer to this question , I learned that SFINAE can be
While I was reading the accepted answer of this question , I had the
Probably an extremely simple answer to this extremely simple question: I'm reading C Primer
I'm asking this question after reading this answer on StackOverflow. The supplied answer works
This question came to mind after reading the answer to this question; which basically
From reading this question and answer , I understand that to clone a local

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.