*Anonymous Coward*
2018-03-05 15:37:10.378067 UTC

1 | Why is the first instance considered to be 'overlappable' instead of 'incoherent'. The manual say: |

2 | "If exactly one non-incoherent candidate remains, select it." |

3 | |

4 | So, why isn't the second candidate chosen? |

5 | |

6 | Besides, why is GHC trying to pick an instance when type variable 'gridFields' is unknown? |

7 | |

8 | ===Class & instances:=== |

9 | {-| Construct a submap 's' from a supermap 't' -} |

10 | class Submap s t where |

11 | submap :: Map t -> Map s |

12 | |

13 | instance {-# INCOHERENT #-} Submap '[] '[] where |

14 | submap xs = Empty |

15 | |

16 | instance {-# INCOHERENT #-} Submap s t => Submap s (x ': t) where |

17 | submap (Ext _ _ xs) = submap xs |

18 | |

19 | instance {-# OVERLAPS #-} Submap s t => Submap (x ': s) (x ': t) where |

20 | submap (Ext k v xs) = Ext k v (submap xs) |

21 | |

22 | ===Error:=== |

23 | • Overlapping instances for Data.Type.Map.Submap |

24 | (Data.Type.Map.Nub |

25 | (Data.Type.Set.Sort |

26 | (Rgr.Pipeline.Internal.Grid.MappingsF UVector gridFields))) |

27 | '["alpha" 'Data.Type.Map.:-> Data.Vector.Unboxed.Base.Vector Int, |

28 | ...] |

29 | arising from a use of ‘project’ |

30 | Matching instances: |

31 | two instances involving out-of-scope types |

32 | instance [overlappable] [safe] Data.Type.Map.Submap s t => |

33 | Data.Type.Map.Submap s (x : t) |

34 | -- Defined in ‘Data.Type.Map’ |

35 | instance [overlap ok] [safe] Data.Type.Map.Submap s t => |

36 | Data.Type.Map.Submap (x : s) (x : t) |

37 | -- Defined in ‘Data.Type.Map’ |

38 | (The choice depends on the instantiation of ‘gridFields’ |

39 | To pick the first instance above, use IncoherentInstances |

40 | when compiling the other instance declarations) |