@@ -306,10 +306,12 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
306 filterModule _ = False
306 filterModule _ = False
308 solve context' (className, tys) trySuperclasses =
308 solve context' (className, tys) trySuperclasses =
309− case chooseSimplestDictionaries (go trySuperclasses className tys) of
310+ dicts = go trySuperclasses className tys
311+ in case sortedNubBy dictTrace (chooseSimplestDictionaries dicts) of
310− [] -> throwError . strMsg $ "No instance found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
312+ [] -> throwError . strMsg $ "No instance found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
311− [dict] -> return (dictionaryValueToValue dict)
313+ [_] -> return $ dictionaryValueToValue $ head dicts
312− _ -> throwError . strMsg $ "Overlapping instances found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
314+ _ -> throwError . strMsg $ "Overlapping instances found for " ++ show className ++ " " ++ unwords (map prettyPrintTypeAtom tys)
314 go trySuperclasses' className' tys' =
316 go trySuperclasses' className' tys' =
315 -- Look for regular type instances
317 -- Look for regular type instances
@@ -385,6 +387,14 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
385 isSimpleDictionaryValue SubclassDictionaryValue{} = False
387 isSimpleDictionaryValue SubclassDictionaryValue{} = False
386 isSimpleDictionaryValue (DependentDictionaryValue _ ds) = all isSimpleDictionaryValue ds
388 isSimpleDictionaryValue (DependentDictionaryValue _ ds) = all isSimpleDictionaryValue ds
387 isSimpleDictionaryValue _ = True
389 isSimpleDictionaryValue _ = True
391+ -- Get the "trace" of a DictionaryValue - that is, remove all SubclassDictionaryValue
392+ -- data constructors
394+ dictTrace :: DictionaryValue -> DictionaryValue
395+ dictTrace (DependentDictionaryValue fnName dicts) = DependentDictionaryValue fnName $ map dictTrace dicts
396+ dictTrace (SubclassDictionaryValue dict _ _) = dict
397+ dictTrace other = other
390-- Check all values in a list pairwise match a predicate
400-- Check all values in a list pairwise match a predicate