@@ -911,12 +911,13 @@ check' (TypedValue checkType val ty1) ty2 = do
911911 kind <- liftCheck $ kindOf moduleName ty1
912912 guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
913913 ty1' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
914− val' <- subsumes (Just val) ty1' ty2
914+ ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty2
915+ val' <- subsumes (Just val) ty1' ty2'
915916 case val' of
916917 Nothing -> throwError . strMsg $ "Unable to check type subsumption"
917918 Just val'' -> do
918− val''' <- if checkType then check val'' ty1' else return val''
919− return $ TypedValue checkType (TypedValue True val''' ty1) ty2
919+ val''' <- if checkType then check val'' ty2' else return val''
920+ return $ TypedValue checkType (TypedValue True val''' ty1') ty2'
920921check' (Case vals binders) ret = do
921922 vals' <- mapM infer vals
922923 let ts = map (\(TypedValue _ _ t) -> t) vals'
@@ -1046,6 +1047,8 @@ checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg ret = do
10461047checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
10471048 dicts <- getTypeClassDictionaries
10481049 checkFunctionApplication' (foldl App fn (map (flip (TypeClassDictionary True) dicts) constraints)) fnTy arg ret
1050+checkFunctionApplication' fn fnTy dict@(TypeClassDictionary _ _ _) _ =
1051+ return (fnTy, App fn dict)
10491052checkFunctionApplication' _ fnTy arg _ = throwError . strMsg $ "Cannot apply a function of type "
10501053 ++ prettyPrintType fnTy
10511054 ++ " to argument " ++ prettyPrintValue arg