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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:00:44+00:00 2026-06-12T11:00:44+00:00

Possible Duplicate: Making (a, a) a Functor I wrote the following implementation of quicksort:

  • 0

Possible Duplicate:
Making (a, a) a Functor

I wrote the following implementation of quicksort:

import Data.List (partition)

quicksort [] = []

quicksort (x:xs) =
    let (smaller, notSmaller) = partition (< x) xs
    in  quicksort smaller ++ x : quicksort notSmaller

Then I wanted to abbreviate the two recursive calls to quicksort by applying fmap to the list pair:

quicksort (x:xs) =
    let (smaller, notSmaller) = fmap quicksort $ partition (< x) xs
    in  smaller ++ x : notSmaller

But apparently, (a, a) is not a functor. Why is that? I tried to provide one:

instance Functor (a, a) where
    fmap f (x, y) = (f x, f y)

But ghci did not like my attempt:

Kind mis-match
The first argument of `Functor' should have kind `* -> *',
but `(a, a)' has kind `*'
In the instance declaration for `Functor (a, a)'

Could anyone explain that error to me? I tried various “fixes”, but none of them worked.

Is it possible to make (a, a) an instance of Functor? Or is the type system not expressive enough?

  • 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-12T11:00:47+00:00Added an answer on June 12, 2026 at 11:00 am

    It’s important to realise that it’s not (a,a) that would be the functor, in the same way that Maybe a and [a] aren’t functors. Instead, the functors are Maybe and [].

    A full explanation requires introducing the concept of kinds, which are like “types of types”. Any concrete type has kind *. A type constructor like Maybe or [] takes a type and returns another type, so it has kind * -> *.

    What’s the kind of (,) (the constructor for pairs)? It needs two types, one for the first slot and one for the second slot, so it has kind * -> * -> *.

    You can only make a functor out of things of kind * -> *, so the short answer to your question is no, you can’t make (,) into a functor.

    However, you can get around the limitation by wrapping the type. For example

    newtype Pair a = P (a,a)
    
    instance Functor Pair where
        fmap f (P (x,y)) = P (f x, f y)
    

    The newtype wrapper will be optimized away by the compiler, so this isn’t any more expensive than what you were trying to do originally – it’s just a little more verbose.

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

Sidebar

Related Questions

Possible Duplicate: Flatten (an irregular) list of lists in Python I have the following
Possible Duplicate: Making a flat list out of list of lists in Python I
Possible Duplicate: Making a flat list out of list of lists in Python how
Possible Duplicate: Making a generic property I'm not quite sure how to do that,
Possible Duplicate: I am making some parts of java image transparent by some code,
Possible Duplicate: CSS Opacity Property I'm making a layer on an image which has
Possible Duplicate: PHP take all combinations I'm thinking of making something in PHP that
Possible Duplicate: Why use getters and setters? Is there any advantage to making methods
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Strip html from strings in python While making a small browser like

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.