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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:23:01+00:00 2026-05-27T06:23:01+00:00

Is it possible to write a function arity :: a -> Integer to determine

  • 0

Is it possible to write a function arity :: a -> Integer to determine the arity of arbitrary functions, such that

> arity map
2
> arity foldr
3
> arity id
1
> arity "hello"
0

?

  • 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-27T06:23:01+00:00Added an answer on May 27, 2026 at 6:23 am

    It’s easy with OverlappingInstances:

    {-# LANGUAGE FlexibleInstances, OverlappingInstances #-}
    
    class Arity f where
      arity :: f -> Int
    
    instance Arity x where
      arity _ = 0
    
    instance Arity f => Arity ((->) a f) where
      arity f = 1 + arity (f undefined) 
    

    Upd Found problem. You need to specify non-polymorphic type for polymorphic functions:

    arity (foldr :: (a -> Int -> Int) -> Int -> [a] -> Int)
    

    Don’t know how to solve this yet.

    Upd2 as Sjoerd Visscher commented below “you have to specify a non-polymorphic type, as the answer depends on which type you choose”.

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

Sidebar

Related Questions

I can see that it's possible to write functions like map/sortBy/findIndex and some other
How can I write (if it's possible at all...) a function which takes an
Is it possible to write a program that will change the phone numbers a
Is it possible to write a script in Perl that opens different URLs and
Would it be possible to write a script that gave the user the ability
Possible Duplicate: Get a function's arity Say I have: function a(x) {}; function b(x,y)
Could you write the easiest possible shell script that will change the desktop wallpaper
Is possible to write language agnostic Robotium tests? For example, if you use a
Is it possible to write a program to do things you constantly do on
Is it possible to write a servlet filter to take inspect HTTP response codes?

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.