Can I tell GHC to arbitrarily choose which instance to use because I don't care?

I have a code like this:

{-# OPTIONS_GHC -Wall #-}
{-# LANUAGE VariousLanguageExtensionsNoneOfWhichWorked #-}

import Control.Applicative
import Data.Either
import Data.Void

class Constructive a where
    lem :: Either (a -> Void) a

instance Constructive Void where
    lem = Left id

instance Num a => Constructive a where
    lem = Right 0

instance Enum a => Constructive a where
    lem = Right $ toEnum 0

instance Bounded a => Constructive a where
    lem = Right minBound

instance Monoid a => Constructive a where
    lem = Right mempty

instance Alternative f => Constructive (f a) where
    lem = Right empty

The problem is that the GHC is complaining about

pad.hs:49:10:
    Duplicate instance declarations:
      instance [overlap ok] Bounded a => Constructive a
        -- Defined at pad.hs:49:10
      instance [overlap ok] Monoid a => Constructive a
        -- Defined at pad.hs:52:10

Along with a bunch of similar errors.

Is there any way to tell the GHC to choose one randomly since I don't care what it uses? (I don't care if he chooses a different one every time I use lem, since that doesn't matter.)

+4
source share
1 answer

This is not the answer to your question, rather as an extended comment suggesting a different route on how to solve the problem.

Haskell newtype , , , , . , .

Haskell 3 , :

SYB GHC Generics. , a -> Void. a -> Void, .

a -> b , a b:

instance (Constructive a, Constructive b) => Constructive (a -> b) where
  ...

x :: b , a -> b const x. a , a -> b absurd. a b , a -> b Void.

Haskell , .

, , GHC , . , ->,

  • SYB , Data. , . :
  • GHC Generics ADT . , instance, Generics.

AdvancedOverlap. , .

+2

Source: https://habr.com/ru/post/1621657/


All Articles