shithub: MicroHs

Download patch

ref: 15867b2838ecef7175c13372738dce1752481035
parent: 61023e37f9f4f45b61a40ea3835123765baaeda8
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Thu Nov 23 10:20:49 EST 2023

Prefer argument dictionaries over instances.

--- a/src/MicroHs/TypeCheck.hs
+++ b/src/MicroHs/TypeCheck.hs
@@ -2320,6 +2320,7 @@
 --                        showIdent di ++ " = " ++ showExpr (EApp de (EVar d)))
                 solve ((d, tupleConstraints ctx) : cnss) uns ((di, EApp de (EVar d)) : sol)
             _           -> tcError loc $ "Multiple constraint solutions for: " ++ showEType ct
+--                                       ++ show (map fst matches)
 
         solveTypeEq loc [t1, t2] cns@(di,_) cnss uns sol = do
           eqs <- gets typeEqTable
@@ -2388,9 +2389,12 @@
 -- Get the best matches.  These are the matches with the smallest substitution.
 getBestMatches :: [(Int, (Expr, [EConstraint]))] -> [(Expr, [EConstraint])]
 getBestMatches [] = []
-getBestMatches ms =
-  let b = minimum (map fst ms)         -- minimum substitution size
-  in  [ ec | (s, ec) <- ms, s == b ]   -- pick out the smallest
+getBestMatches ams =
+  let (args, insts) = partition (\ (_, (EVar i, _)) -> "adict$" `isPrefixOf` unIdent i) ams
+      pick ms =
+        let b = minimum (map fst ms)         -- minimum substitution size
+        in  [ ec | (s, ec) <- ms, s == b ]   -- pick out the smallest
+  in  if null args then pick insts else pick args
 
 -- Check that there are no unsolved constraints.
 checkConstraints :: T ()
--