on master help sign in
Improve missing args type diff

Try to unify the arguments after the missing args. This way, if they match, the type diff will not highlight things like String does not match a. Instead they’ll both be strings.

commit4d800cd4e1a540ba4d9e2b639e05c333c6c71a64 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 9 Aug 2016, 21:58 (10 years ago) parent267f708
1 file changed+22−12
src/Type/Unify.hs+22−12
src/Type/Unify.hs+22−12
@@ -77,14 +77,19 @@ newtype Mismatch =
7777
7878
7979mismatch :: Context -> Maybe Error.Reason -> Unify a
80−mismatch (Context orientation var1 _ var2 _) maybeReason =
81− do numArgs1 <- liftIO $ countArgs var1
82− numArgs2 <- liftIO $ countArgs var2
83− mismatchHelp orientation $
84− if numArgs1 == numArgs2 then
85− maybeReason
80+mismatch context@(Context orientation var1 _ var2 _) maybeReason =
81+ do args1 <- liftIO $ collectArgs var1
82+ args2 <- liftIO $ collectArgs var2
83+
84+ let numArgs1 = length args1
85+ let numArgs2 = length args2
86+
87+ if numArgs1 == numArgs2
88+ then
89+ mismatchHelp orientation maybeReason
8690 else
87− Just (Error.MissingArgs (abs (numArgs2 - numArgs1)))
91+ do zipWithM_ (\arg1 arg2 -> lift $ runExceptT $ subUnify context arg1 arg2) args1 args2
92+ mismatchHelp orientation $ Just $ Error.MissingArgs $ abs (numArgs2 - numArgs1)
8893
8994
9095mismatchHelp :: Orientation -> Maybe Error.Reason -> Unify a
@@ -455,15 +460,20 @@ collectAppsHelp args content =
455460 return Other
456461
457462
458−countArgs :: Variable -> IO Int
459−countArgs variable =
463+collectArgs :: Variable -> IO [Variable]
464+collectArgs variable =
465+ collectArgsHelp [] variable
466+
467+
468+collectArgsHelp :: [Variable] -> Variable -> IO [Variable]
469+collectArgsHelp revArgs variable =
460470 do content <- getContent variable
461471 case content of
462− Structure (Fun1 _ returnType) ->
463− (+1) <$> countArgs returnType
472+ Structure (Fun1 arg returnType) ->
473+ collectArgsHelp (arg : revArgs) returnType
464474
465475 _ ->
466− return 0
476+ return $ variable : revArgs
467477
468478
469479getContent :: Variable -> IO Content