**Paste:**#363156**Author:**Anonymous Coward**Language:**Haskell**Channel:**#haskell Context in IRC logs**Created:**2018-03-05 15:37:10 UTC**Revisions:**- 2018-03-05 15:50:56 UTC #363160 (diff): Overlapping instances problem (Anonymous Coward)
- 2018-03-05 15:46:53 UTC #363159 (diff): Overlapping instances problem (Anonymous Coward)
- 2018-03-05 15:45:58 UTC #363158 (diff): Overlapping instances problem (Anonymous Coward)
- 2018-03-05 15:45:19 UTC #363157 (diff): Overlapping instances problem (Anonymous Coward)
- 2018-03-05 15:37:10 UTC #363156: Overlapping instances problem (Anonymous Coward)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | GHC doesn't like the way I call 'project' in 'foo'. 1. Why is the first instance considered to be [overlappable] instead of [incoherent] (I marked it with "INCOHERENT")? The manual say: "If exactly one non-incoherent candidate remains, select it." So, why isn't the second (non-incoherent) candidate chosen? 2. Besides, why is GHC even trying to pick an instance of 'Submap' when type variable 'gridFields' is yet uninstantiated? ===Class & instances:=== {-| Construct a submap 's' from a supermap 't' -} class Submap s t where submap :: Map t -> Map s instance {-# INCOHERENT #-} Submap '[] '[] where submap xs = Empty instance {-# INCOHERENT #-} Submap s t => Submap s (x ': t) where submap (Ext _ _ xs) = submap xs instance {-# OVERLAPS #-} Submap s t => Submap (x ': s) (x ': t) where submap (Ext k v xs) = Ext k v (submap xs) ===Offending code calling 'project':=== foo :: forall (pointFields :: [Symbol]) (gridFields :: [Symbol]). SignalTaskConfig pointFields gridFields -> Subgrid gridFields foo SignalTaskConfig{session, point, modelConfig, context} = let Context{mdRoot, binRoot, cacheRoot, feeSession} = unFastPathComparison context ModelConfig{sym, grid, universe, projectC2, projectD2} = unFastPathComparison modelConfig in project @(RecFields (Subgrid gridFields)) grid ===Error:=== • Overlapping instances for Data.Type.Map.Submap (Data.Type.Map.Nub (Data.Type.Set.Sort (Rgr.Pipeline.Internal.Grid.MappingsF UVector gridFields))) '["alpha" 'Data.Type.Map.:-> Data.Vector.Unboxed.Base.Vector Int, ...] arising from a use of ‘project’ Matching instances: two instances involving out-of-scope types instance [overlappable] [safe] Data.Type.Map.Submap s t => Data.Type.Map.Submap s (x : t) -- Defined in ‘Data.Type.Map’ instance [overlap ok] [safe] Data.Type.Map.Submap s t => Data.Type.Map.Submap (x : s) (x : t) -- Defined in ‘Data.Type.Map’ (The choice depends on the instantiation of ‘gridFields’ To pick the first instance above, use IncoherentInstances when compiling the other instance declarations) |