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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:11:05+00:00 2026-06-10T07:11:05+00:00

While trying to define some mathematical objects using the Numeric prelude I’ve run into

  • 0

While trying to define some mathematical objects using the Numeric prelude I’ve run into a problem. The Additive typeclass defines an instance

instance Additive.C v => Additive.C [v]

Which I read “if v is Additive, [v] is too” (apparently I was wrong here). It’s implemented something like

(+) x y = map (\(a,b) -> a + b) $ zip x y

So that [1,2,3] + [4,5,6] = [5,7,9] which is useless for what I want to do. I assumed I wouldn’t have a problem as my v type isn’t Additive. Unfortunately I still got an overlapping instances error which I found very confusing. I’ve did a little reading and I now understand that for some reason, Haskell ignores everything before the “=>” bit so I should have read the default instance as “any list is potentially additive in the sense of the default instance”. I’ve tried using OverlappingInstances despite the fact that this extension has the reputation of being “dangerous”, but even that doesn’t seem to help.

Here is my testcase.

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE MultiParamTypeClasses,FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-} --This doesn't seem to help
import NumericPrelude

import qualified Algebra.Additive    as Additive

data Test = Red | Green | Blue deriving Show

instance Additive.C [Test] where
   zero = undefined
   (+) =  undefined
   negate = undefined

test = [Red] + [Green] + [Blue]

Produces the error (Update: this appears to only happen in older versions of GHC. version 7.2.2 seems to accept it):

Overlapping instances for Additive.C [Test]
  arising from a use of `+'
Matching instances:
  instance Additive.C v => Additive.C [v]
    -- Defined in Algebra.Additive
  instance [overlap ok] Additive.C [Test]
    -- Defined at Testcase.hs:10:10-26
In the first argument of `(+)', namely `[Red] + [Green]'
In the expression: [Red] + [Green] + [Blue]
In an equation for `test': test = [Red] + [Green] + [Blue]

Does this mean I can’t use lists because I don’t want to default instance of Additive? What I really want to do is tell ghc to just forget that default instance, it that possible? If not, I’m not sure where to go from here other than dropping lists.

  • 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-10T07:11:06+00:00Added an answer on June 10, 2026 at 7:11 am

    Edit: As @kosmikus mentioned, your example works well for me, too. I am using ghc 7.4.1.

    You cannot make the compiler forget the instance as it is imported as soon as you import the module, the instance is defined in. Note that OverlappingInstances does not tell the compiler to forget an instance but to take the most specify instance that is available.

    In order to prevent overlapping instances you can use a type wrapper that is used to distinguish arbitrary lists from the lists you are using. For example, you can define

    data TestList = TestList [Test]
    

    Then, you can define a custom instance of the type class for TestList. In most cases, people use record syntax to define an accessor for the list as you have to wrap and unwrap the lists.

    data TestList = TestList { list :: [Test] }
    

    In order to reduce the cost of the additional constructor you can use a newtype instead of a data.

    newtype TestList = TestList { list :: [Test] }
    

    A newtype may only have a single argument and the compiler basically handles it as if it wasn’t there but uses the type information, which the constructor provides, to distinguish your lists from arbitrary lists when choosing the correct instance.

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

Sidebar

Related Questions

While trying to implement some jQuery UI Tabs using AJAX I keep running into
I'm having a bit of an odd problem while trying to compile some code
While trying to troubleshoot a problem I'm having with a project, I noticed that
While trying to add value into foreign key field, if same data doesn't exist
I'm trying to define some default behaviours for my jQuery Dialogs like the following:
I'm trying to write some microcontroller code using Texas Instruments examples, and it uses
I'm using the following to define root while in development: define('LOCAL_URL', 'http://localhost/~xampp/Mysite'); define('REMOTE_URL', 'http://example.com');
I am trying to show a spinning progress while I load some data, but
I am trying to define dynamically variables. I am using a function for this,
I am trying to use AutoMapper to map some DTO (data contract) objects received

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.