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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:04:07+00:00 2026-05-19T17:04:07+00:00

How can I make (a, a) a Functor without resorting to a newtype ?

  • 0

How can I make (a, a) a Functor without resorting to a newtype?

Basically I want it to work like this:

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

But of course that’s not a legal way to express it:

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

What I really want is a type-level function like this: \a -> (a, a) (invalid syntax). So a type alias, perhaps?

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

I would think this would work, but it doesn’t. First I get this complaint:

Illegal instance declaration for `Functor V2'
(All instance types must be of the form (T t1 ... tn)
 where T is not a synonym.
 Use -XTypeSynonymInstances if you want to disable this.)
In the instance declaration for `Functor V2'

If I follow the advice and add the TypeSynonymInstances extension, I get a new error:

Type synonym `V2' should have 1 argument, but has been given 0
In the instance declaration for `Functor V2'

Well, duh, that’s the point! V2 has kind * -> * which is what is required of a Functor instance. Well, ok, I can use a newtype like this:

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

But now I’ve got to sprinkle V2s liberally throughout my code instead of just being able to deal with simple tuples, which kind of defeats the point of making it a Functor; at that point I might as well make my own function vmap :: (a -> b) -> (a, a) -> (b, b).

So is there any way to do this nicely, i.e. without a newtype?

  • 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-19T17:04:07+00:00Added an answer on May 19, 2026 at 5:04 pm

    As others have stated, there’s no way to do this without resorting to newtypes or data declarations. However, have you looked at Control.Arrow? Many of those functions are very useful with tuples, for example:

    vmap :: (a -> b) -> (a,a) -> (b,b)
    vmap f = f *** f
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish I can make an image gallery without using jQuery plugin. Which all
I know I can make a method like private T MyFun<T>() where T :
How i can make a decision to use Linq or Entity Framework as data
How i can make an xml file from NSString object? In other words, how
How I can make SFTP transport through SSHClient on the remote server? I have
how i can make a list on canvas in an application having more then
how i can make svnlook tree view just 2 level ?
I know I can make my button's image bigger when it is focused using
how i can make windows server 2003 see some directory from UNIX-AIX ? i
I've the following situation: module type M = sig type s = ... end

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.