git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Choose simplest superclass instance
1138e3bPhil Freeman
examples/failing/438.purs+1−1
@@ -1,4 +1,4 @@
1−-- @shouldFailWith NoInstanceFound
1+-- @shouldFailWith PossiblyInfiniteInstance
2
2
3-- See issue 438 for details: this test is mainly here to test that code like
3-- See issue 438 for details: this test is mainly here to test that code like
4-- this doesn't cause the compiler to loop.
4-- this doesn't cause the compiler to loop.
src/Language/PureScript/TypeChecker/Entailment.hs+2−2
@@ -78,8 +78,8 @@ entails env moduleName context = solve
78 unique :: [(a, TypeClassDictionaryInScope)] -> Check (a, TypeClassDictionaryInScope)
78 unique :: [(a, TypeClassDictionaryInScope)] -> Check (a, TypeClassDictionaryInScope)
79 unique [] = throwError . errorMessage $ NoInstanceFound className' tys'
79 unique [] = throwError . errorMessage $ NoInstanceFound className' tys'
80 unique [a] = return a
80 unique [a] = return a
81− unique xs@(x : _) | pairwise overlapping (map snd xs) = throwError . errorMessage $ OverlappingInstances className' tys' (map (tcdName . snd) xs) -- TODO: use simplest instance
81+ unique tcds | pairwise overlapping (map snd tcds) = throwError . errorMessage $ OverlappingInstances className' tys' (map (tcdName . snd) tcds)
82− | otherwise = return x
82+ | otherwise = return (minimumBy (compare `on` length . tcdPath . snd) tcds)
83
83
84 -- |
84 -- |
85 -- Check if two dictionaries are overlapping
85 -- Check if two dictionaries are overlapping