Questions tagged [overlapping-instances]

Questions related to GHC haskell's `OverlappingInstances` extension

45 questions
10
votes
1 answer

Can I use OverlappingInstances to get nicer error messages?

I'm currently dealing with some Haskell code that I didn't write, but that I've made changes to. After my changes, I run the program and get the following error message: Prelude.!!: index too large The call to !! is not in my code, so refactoring…
jmite
  • 7,320
  • 6
  • 32
  • 74
10
votes
1 answer

Resolving overlapping instances in external library

I'm trying to show something of type Tagged s b (Data.Tagged) in a module that also imports from the accelerate library. Unfortunately, the accelerate library defines the show instance instance Kit acc => Show (acc aenv a) where in…
crockeea
  • 21,467
  • 10
  • 44
  • 93
8
votes
1 answer

Are there any language extensions or language descendants of Haskell, that favor expressiveness, particularly in instance handling?

At times, I run into the "feature" that Haskell only matches instance heads, namely, instance (a ~ NewDataTyp b) => C a will now match any type whatsoever, i.e. writing another instance declaration of C in your program will is an error, even if it…
gatoatigrado
  • 16,008
  • 13
  • 77
  • 136
8
votes
1 answer

Haskell overlapping instances and type functions

I have the following typeclass which models a SQL-like query optimization: class OptimizableQuery q where type Optimized q :: * optimize :: q -> Optimized q instance Query q => OptimizableQuery q where type Optimized q = q optimize q =…
5
votes
1 answer

Overlapping instances error when trying to write fallback instance

I'm trying to do something similar to the advanced overlap trick to define an instance with overlapping behavior. I'm trying to derive an instance for a tuple that will use an instance for the fst field if one exists, otherwise use the instance for…
4
votes
1 answer

Help interpreting overlapping instances error message

I'm stumped on this overlapping instances error message. Sorry this is a nontrivial project, but the error should be local to the type signatures. First, I declare f to be of a certain type, let f = undefined :: (CompNode Int) Then, I try to call…
gatoatigrado
  • 16,008
  • 13
  • 77
  • 136
4
votes
1 answer

Overlapping instances via Nat-kind

This problem actually emerged from attempt to implement few mathematical groups as types. Cyclic groups have no problem (instance of Data.Group defined elsewhere): newtype Cyclic (n :: Nat) = Cyclic {cIndex :: Integer} deriving (Eq, Ord) cyclic ::…
Dannyu NDos
  • 1,889
  • 11
  • 28
4
votes
2 answers

MonadError instance for a Free Monad

I have created a very useful Free Monad out of a sum data type. That abstracts access to a persistent data store: data DataStoreF next = Create Asset ( String -> next) | Read String …
John F. Miller
  • 25,556
  • 8
  • 66
  • 120
4
votes
1 answer

Make a typeclass instance automatically an instance of another

What I'd like to achieve is that any instance of the following class (SampleSpace) should automatically be an instance of Show, because SampleSpace contains the whole interface necessary to create a String representation and hence all possible…
Sventimir
  • 1,653
  • 3
  • 13
  • 21
4
votes
1 answer

With PolyKinds and OverlappingInstances, writing an instance for (t :: k) fully applied to k arguments

It seems as though this isn't possible, but here's an example of what I have working: {-# LANGUAGE PolyKinds , MultiParamTypeClasses , FlexibleInstances , OverlappingInstances #-} data Proxy a = Proxy class Test pt t where test :: pt -> t ->…
jberryman
  • 15,764
  • 4
  • 39
  • 77
3
votes
1 answer

Functional dependencies and overlapping instances

I have a typeclass with a fundep: {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE FlexibleInstances #-} class C a b | a -> b I want to provide specific instances: instance C A B As well as a general, default instance: instance C a…
3
votes
0 answers

Multi-way FunDeps and consistency with Overlapping Instances: (why) does this work?

This is a variation on an old chestnut. I wrote it expecting it not to work, but it did. Or is it dodgy? (At GHC 8.6.5.) {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, FunctionalDependencies,…
AntC
  • 1,993
  • 9
  • 15
3
votes
1 answer

Why does this function using a typeclass with overlapping instances behave differently in GHCi?

Background I have written the following code in Haskell (GHC 8.6.3): {-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, TypeFamilies, UndecidableInstances, AllowAmbiguousTypes #-} import…
tophat
  • 579
  • 4
  • 9
3
votes
0 answers

In GHC-8.2.2, can overlapping instance resolution depend on whether a file is included as an exposed module?

I'm encountering the following hard to understand behavior from GHC-8.2.2 I have some overlapping typeclass instances. No incoherent typeclass instances. There's a certain typeclass instance of the form, roughly, instance (C f h, C g h) => D1 (D2 f…
3
votes
1 answer

How are these two instances overlapping (involving out-of-scope types)

I couple of days ago I asked a question about injecting functors in the context of free-monads. The solution suggested there, based on Data Types à la Carte uses a class that represents a sort of containment relationship between functors. -- | Class…
Damian Nadales
  • 4,603
  • 1
  • 20
  • 30
1
2 3