Questions related to GHC haskell's `OverlappingInstances` extension
Questions tagged [overlapping-instances]
42 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
- 8,171
- 6
- 40
- 81
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,651
- 10
- 48
- 101
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,580
- 18
- 81
- 143
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 =…

Giuseppe Maggiore
- 2,011
- 1
- 23
- 31
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…

Cirdec
- 24,019
- 2
- 50
- 100
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,580
- 18
- 81
- 143
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
- 2,458
- 13
- 32
4
votes
1 answer
GHC Overlapping instances when generalising addition
Trying to generalise (+) to more than just Nums, I wrote a up an Addable class:
{-# LANGUAGE FlexibleContexts, FlexibleInstances, UndecidableInstances #-}
class Addable a where
(+) :: Addable a => a -> a -> a
instance Addable [a] where
(+) =…

ThreeFx
- 7,250
- 1
- 27
- 51
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
- 26,961
- 10
- 71
- 121
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,996
- 3
- 14
- 25
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
- 16,334
- 5
- 42
- 83
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…

Graham Leach-Krouse
- 143
- 6
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,907
- 1
- 21
- 34
3
votes
2 answers
Moving function call into where clause breaks type checker with OverlappingInstances
I was using OverlappingInstances to make a pretty print class that would default to Show whenever I didn't provide a custom instance for some type.
For some reason this seems to break whenever you use a where clause or a let expression.
{-# LANGUAGE…

semicolon
- 2,530
- 27
- 37
3
votes
0 answers
Strange program that requires incoherent instances yet always seems to pick the "right" one?
Consider the following program, which only compiles with incoherent instances enabled:
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-}
{-# LANGUAGE IncoherentInstances #-}
main = do
print (g (undefined :: Int))
print (g…

Clinton
- 22,361
- 15
- 67
- 163