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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:35:44+00:00 2026-06-04T02:35:44+00:00

data Vector a = Vector a a a deriving (Eq, Show) instance Functor Vector

  • 0
data Vector a = Vector a a a deriving (Eq, Show)

instance Functor Vector where
    fmap f (Vector x y z) = Vector (f x) (f y) (f z)

So far so good.

instance Num ((Num a) => Vector a) where
    negate = fmap negate

Doesn’t work. I tried many different variations on that first line but GHC keeps complaining. I want to make a Vector containing numbers an instance of Num; surely this should be possible? Otherwise I would have to make an instance for Int, Integer, Float, Double, etc. all with the same definition.

  • 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-04T02:35:46+00:00Added an answer on June 4, 2026 at 2:35 am
    instance Num a => Num (Vector a) where
       negate = fmap negate
    

    Consider writing other methods too.

    (You can write deriving (Eq, Show, Functor) if you turn on -XDeriveFunctor.)

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

Sidebar

Related Questions

I wrote a storable vector instance for the data type below ( original question
I have a large nested vector that look like this: import Data.Vector let x
Say I have a vector: (def data [Hello World Test This]) And I want
I'd like a generic method for retrieving the data from a vector. I have
I have some data structures: all_unordered_m is a big vector containing all the strings
I'm having some trouble reading data from a file into a vector of Orders.
I'm using the support vector machine from the e1071 package to classify my data
I am trying to declare a private Data Structure such as the Vector in
I've got raw data streams from image files, like: vector<char> rawData(fileSize); ifstream inFile(image.jpg); inFile.read(&rawData[0]);
I have a vector<set<char> > data structure (transactions database) and I want to know

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.