@@ -95,15 +95,7 @@ unifyTypes t1 t2 = rethrow (\e -> "Error unifying type " ++ prettyPrintType t1 +
9595 sk <- skolemize ident ty1
9696 sk `unifyTypes` ty2
9797 unifyTypes' ty f@(ForAll _ _) = f `unifyTypes` ty
98− unifyTypes' Number Number = return ()
99− unifyTypes' String String = return ()
100− unifyTypes' Boolean Boolean = return ()
101− unifyTypes' Array Array = return ()
10298 unifyTypes' (Object row1) (Object row2) = row1 ?= row2
103− unifyTypes' (Function args1 ret1) (Function args2 ret2) = do
104− guardWith "Function applied to incorrect number of args" $ length args1 == length args2
105− zipWithM_ unifyTypes args1 args2
106− ret1 `unifyTypes` ret2
10799 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
108100 unifyTypes' (TypeConstructor c1) (TypeConstructor c2) = do
109101 env <- getEnv
@@ -235,14 +227,19 @@ entails moduleName context goal@(className, ty) = do
235227 , typeConstructorsAreEqual env moduleName className' (tcdClassName tcd)
236228 , subst <- maybeToList $ typeHeadsAreEqual moduleName env ty' (tcdInstanceType tcd)
237229 , args <- solveSubgoals env subst (tcdDependencies tcd) ]
230+ solveSubgoals :: Environment -> [(String, Type)] -> Maybe [(Qualified ProperName, Type)] -> [Maybe [Value]]
238231 solveSubgoals _ _ Nothing = return Nothing
239232 solveSubgoals env subst (Just subgoals) = do
240233 dict <- mapM (go env) (replaceAllTypeVars subst subgoals)
241234 return $ Just dict
242− mkDictionary fnName args = maybe id (flip App) args $ (Var fnName)
235+ mkDictionary :: Qualified Ident -> Maybe [Value] -> Value
236+ mkDictionary fnName Nothing = Var fnName
237+ mkDictionary fnName (Just dicts) = foldr (flip App) (Var fnName) dicts
238+ filterModule :: TypeClassDictionaryInScope -> Bool
243239 filterModule (TypeClassDictionaryInScope { tcdName = Qualified (Just mn) _ }) | mn == moduleName = True
244240 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
245241 filterModule _ = False
242+ canonicalizeDictionary :: TypeClassDictionaryInScope -> Qualified Ident
246243 canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDRegular, tcdName = nm }) = nm
247244 canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDAlias nm }) = nm
248245
@@ -251,11 +248,7 @@ entails moduleName context goal@(className, ty) = do
251248-- and return a substitution from type variables to types which makes the type heads unify.
252249--
253250typeHeadsAreEqual :: ModuleName -> Environment -> Type -> Type -> Maybe [(String, Type)]
254−typeHeadsAreEqual _ _ String String = Just []
255−typeHeadsAreEqual _ _ Number Number = Just []
256−typeHeadsAreEqual _ _ Boolean Boolean = Just []
257251typeHeadsAreEqual _ _ (Skolem s1) (Skolem s2) | s1 == s2 = Just []
258−typeHeadsAreEqual _ _ Array Array = Just []
259252typeHeadsAreEqual m e (TypeConstructor c1) (TypeConstructor c2) | typeConstructorsAreEqual e m c1 c2 = Just []
260253typeHeadsAreEqual m e (TypeApp h1 (TypeVar v)) (TypeApp h2 arg) = (:) (v, arg) <$> typeHeadsAreEqual m e h1 h2
261254typeHeadsAreEqual m e t1@(TypeApp _ _) t2@(TypeApp _ (TypeVar _)) = typeHeadsAreEqual m e t2 t1
@@ -387,13 +380,13 @@ infer val = rethrow (\e -> "Error inferring type of term " ++ prettyPrintValue v
387380-- Infer a type for a value
388381--
389382infer' :: Value -> UnifyT Check Value
390−infer' v@(NumericLiteral _) = return $ TypedValue True v Number
391−infer' v@(StringLiteral _) = return $ TypedValue True v String
392−infer' v@(BooleanLiteral _) = return $ TypedValue True v Boolean
383+infer' v@(NumericLiteral _) = return $ TypedValue True v tyNumber
384+infer' v@(StringLiteral _) = return $ TypedValue True v tyString
385+infer' v@(BooleanLiteral _) = return $ TypedValue True v tyBoolean
393386infer' (ArrayLiteral vals) = do
394387 ts <- mapM infer vals
395388 els <- fresh
396− forM_ ts $ \(TypedValue _ _ t) -> els ?= TypeApp Array t
389+ forM_ ts $ \(TypedValue _ _ t) -> els ?= TypeApp tyArray t
397390 return $ TypedValue True (ArrayLiteral ts) els
398391infer' (Unary op val) = do
399392 v <- infer val
@@ -418,9 +411,9 @@ infer' (ObjectUpdate o ps) = do
418411 return $ TypedValue True (ObjectUpdate o' newVals) $ Object $ rowFromList (newTys, row)
419412infer' (Indexer index val) = do
420413 el <- fresh
421− index' <- check index Number
422− val' <- check val (TypeApp Array el)
423− return $ TypedValue True (Indexer (TypedValue True index' Number) (TypedValue True val' (TypeApp Array el))) el
414+ index' <- check index tyNumber
415+ val' <- check val (TypeApp tyArray el)
416+ return $ TypedValue True (Indexer (TypedValue True index' tyNumber) (TypedValue True val' (TypeApp tyArray el))) el
424417infer' (Accessor prop val) = do
425418 typed@(TypedValue _ _ objTy) <- infer val
426419 propTy <- inferProperty objTy prop
@@ -431,16 +424,16 @@ infer' (Accessor prop val) = do
431424 _ <- subsumes Nothing objTy (Object (RCons prop field rest))
432425 return $ TypedValue True (Accessor prop typed) field
433426 Just ty -> return $ TypedValue True (Accessor prop typed) ty
434−infer' (Abs args ret) = do
435− ts <- replicateM (length args) fresh
427+infer' (Abs arg ret) = do
428+ ty <- fresh
436429 Just moduleName <- checkCurrentModule <$> get
437− bindLocalVariables moduleName (zip args ts) $ do
430+ bindLocalVariables moduleName [(arg, ty)] $ do
438431 body@(TypedValue _ _ bodyTy) <- infer' ret
439− return $ TypedValue True (Abs args body) $ Function ts bodyTy
440−infer' (App f args) = do
432+ return $ TypedValue True (Abs arg body) $ function ty bodyTy
433+infer' (App f arg) = do
441434 f'@(TypedValue _ _ ft) <- infer f
442435 ret <- fresh
443− app <- checkFunctionApplication f' ft args ret
436+ app <- checkFunctionApplication f' ft arg ret
444437 return $ TypedValue True app ret
445438infer' (Var var) = do
446439 Just moduleName <- checkCurrentModule <$> get
@@ -450,7 +443,7 @@ infer' (Var var) = do
450443 ConstrainedType constraints _ -> do
451444 env <- getEnv
452445 dicts <- getTypeClassDictionaries
453− return $ TypedValue True (App (Var var) (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) ty'
446+ return $ TypedValue True (foldl App (Var var) (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) ty'
454447 _ -> return $ TypedValue True (Var var) ty'
455448infer' (Block ss) = do
456449 ret <- fresh
@@ -470,7 +463,7 @@ infer' (Case vals binders) = do
470463 binders' <- checkBinders (map (\(TypedValue _ _ t) -> t) ts) ret binders
471464 return $ TypedValue True (Case ts binders') ret
472465infer' (IfThenElse cond th el) = do
473− cond' <- check cond Boolean
466+ cond' <- check cond tyBoolean
474467 v2@(TypedValue _ _ t2) <- infer th
475468 v3@(TypedValue _ _ t3) <- infer el
476469 t2 ?= t3
@@ -525,9 +518,9 @@ checkUnary op val res =
525518-- Built-in unary operators
526519--
527520unaryOps :: [(UnaryOperator, (Type, Type))]
528−unaryOps = [ (Negate, (Number, Number))
529− , (Not, (Boolean, Boolean))
530− , (BitwiseNot, (Number, Number))
521+unaryOps = [ (Negate, (tyNumber, tyNumber))
522+ , (Not, (tyBoolean, tyBoolean))
523+ , (BitwiseNot, (tyNumber, tyNumber))
531524 ]
532525
533526-- |
@@ -536,7 +529,7 @@ unaryOps = [ (Negate, (Number, Number))
536529inferBinary :: BinaryOperator -> Value -> Value -> UnifyT Check Value
537530inferBinary op left@(TypedValue _ _ leftTy) right@(TypedValue _ _ rightTy) | isEqualityTest op = do
538531 leftTy ?= rightTy
539− return $ TypedValue True (Binary op left right) Boolean
532+ return $ TypedValue True (Binary op left right) tyBoolean
540533inferBinary op left@(TypedValue _ _ leftTy) right@(TypedValue _ _ rightTy) =
541534 case fromMaybe (error "Invalid operator") $ lookup op binaryOps of
542535 (valTy, resTy) -> do
@@ -550,7 +543,7 @@ inferBinary _ _ _ = error "Invalid arguments to inferBinary"
550543--
551544checkBinary :: BinaryOperator -> Value -> Value -> Type -> UnifyT Check Value
552545checkBinary op left right res | isEqualityTest op = do
553− res ?= Boolean
546+ res ?= tyBoolean
554547 left'@(TypedValue _ _ t1) <- infer left
555548 right'@(TypedValue _ _ t2) <- infer right
556549 t1 ?= t2
@@ -575,24 +568,24 @@ isEqualityTest _ = False
575568-- Built-in binary operators
576569--
577570binaryOps :: [(BinaryOperator, (Type, Type))]
578−binaryOps = [ (Add, (Number, Number))
579− , (Subtract, (Number, Number))
580− , (Multiply, (Number, Number))
581− , (Divide, (Number, Number))
582− , (Modulus, (Number, Number))
583− , (BitwiseAnd, (Number, Number))
584− , (BitwiseOr, (Number, Number))
585− , (BitwiseXor, (Number, Number))
586− , (ShiftRight, (Number, Number))
587− , (ZeroFillShiftRight, (Number, Number))
588− , (And, (Boolean, Boolean))
589− , (Or, (Boolean, Boolean))
590− , (Concat, (String, String))
591− , (Modulus, (Number, Number))
592− , (LessThan, (Number, Boolean))
593− , (LessThanOrEqualTo, (Number, Boolean))
594− , (GreaterThan, (Number, Boolean))
595− , (GreaterThanOrEqualTo, (Number, Boolean))
571+binaryOps = [ (Add, (tyNumber, tyNumber))
572+ , (Subtract, (tyNumber, tyNumber))
573+ , (Multiply, (tyNumber, tyNumber))
574+ , (Divide, (tyNumber, tyNumber))
575+ , (Modulus, (tyNumber, tyNumber))
576+ , (BitwiseAnd, (tyNumber, tyNumber))
577+ , (BitwiseOr, (tyNumber, tyNumber))
578+ , (BitwiseXor, (tyNumber, tyNumber))
579+ , (ShiftRight, (tyNumber, tyNumber))
580+ , (ZeroFillShiftRight, (tyNumber, tyNumber))
581+ , (And, (tyBoolean, tyBoolean))
582+ , (Or, (tyBoolean, tyBoolean))
583+ , (Concat, (tyString, tyString))
584+ , (Modulus, (tyNumber, tyNumber))
585+ , (LessThan, (tyNumber, tyBoolean))
586+ , (LessThanOrEqualTo, (tyNumber, tyBoolean))
587+ , (GreaterThan, (tyNumber, tyBoolean))
588+ , (GreaterThanOrEqualTo, (tyNumber, tyBoolean))
596589 ]
597590
598591-- |
@@ -600,9 +593,9 @@ binaryOps = [ (Add, (Number, Number))
600593--
601594inferBinder :: Type -> Binder -> UnifyT Check (M.Map Ident Type)
602595inferBinder _ NullBinder = return M.empty
603−inferBinder val (StringBinder _) = val ?= String >> return M.empty
604−inferBinder val (NumberBinder _) = val ?= Number >> return M.empty
605−inferBinder val (BooleanBinder _) = val ?= Boolean >> return M.empty
596+inferBinder val (StringBinder _) = val ?= tyString >> return M.empty
597+inferBinder val (NumberBinder _) = val ?= tyNumber >> return M.empty
598+inferBinder val (BooleanBinder _) = val ?= tyBoolean >> return M.empty
606599inferBinder val (VarBinder name) = return $ M.singleton name val
607600inferBinder val (NullaryBinder ctor) = do
608601 env <- getEnv
@@ -619,7 +612,7 @@ inferBinder val (UnaryBinder ctor binder) = do
619612 Just (ty, _) -> do
620613 fn <- replaceAllVarsWithUnknowns ty
621614 case fn of
622− Function [obj] ret -> do
615+ TypeApp (TypeApp t obj) ret | t == tyFunction -> do
623616 _ <- subsumes Nothing val ret
624617 inferBinder obj binder
625618 _ -> throwError $ "Constructor " ++ show ctor ++ " is not a unary constructor"
@@ -641,13 +634,13 @@ inferBinder val (ObjectBinder props) = do
641634inferBinder val (ArrayBinder binders) = do
642635 el <- fresh
643636 m1 <- M.unions <$> mapM (inferBinder el) binders
644− val ?= TypeApp Array el
637+ val ?= TypeApp tyArray el
645638 return m1
646639inferBinder val (ConsBinder headBinder tailBinder) = do
647640 el <- fresh
648641 m1 <- inferBinder el headBinder
649642 m2 <- inferBinder val tailBinder
650− val ?= TypeApp Array el
643+ val ?= TypeApp tyArray el
651644 return $ m1 `M.union` m2
652645inferBinder val (NamedBinder name binder) = do
653646 m <- inferBinder val binder
@@ -666,7 +659,7 @@ checkBinders nvals ret ((binders, grd, val):bs) = do
666659 case grd of
667660 Nothing -> return (binders, Nothing, val')
668661 Just g -> do
669− g' <- check g Boolean
662+ g' <- check g tyBoolean
670663 return (binders, Just g', val')
671664 rs <- checkBinders nvals ret bs
672665 return $ r : rs
@@ -698,7 +691,7 @@ checkStatement mass _ (Assignment ident val) = do
698691 Just ty -> do t ?= ty
699692 return (False, mass, Assignment ident val')
700693checkStatement mass ret (While val inner) = do
701− val' <- check val Boolean
694+ val' <- check val tyBoolean
702695 (allCodePathsReturn, _, inner') <- checkBlock mass ret inner
703696 return (allCodePathsReturn, mass, While val' inner')
704697checkStatement mass ret (If ifst) = do
@@ -707,9 +700,9 @@ checkStatement mass ret (If ifst) = do
707700checkStatement mass ret (For ident start end inner) = do
708701 Just moduleName <- checkCurrentModule <$> get
709702 assignVariable ident
710− start' <- check start Number
711− end' <- check end Number
712− (allCodePathsReturn, _, inner') <- bindLocalVariables moduleName [(ident, Number)] $ checkBlock mass ret inner
703+ start' <- check start tyNumber
704+ end' <- check end tyNumber
705+ (allCodePathsReturn, _, inner') <- bindLocalVariables moduleName [(ident, tyNumber)] $ checkBlock mass ret inner
713706 return (allCodePathsReturn, mass, For ident start' end' inner')
714707checkStatement mass ret (Return val) = do
715708 val' <- check val ret
@@ -720,11 +713,11 @@ checkStatement mass ret (Return val) = do
720713--
721714checkIfStatement :: M.Map Ident Type -> Type -> IfStatement -> UnifyT Check (Bool, IfStatement)
722715checkIfStatement mass ret (IfStatement val thens Nothing) = do
723− val' <- check val Boolean
716+ val' <- check val tyBoolean
724717 (_, _, thens') <- checkBlock mass ret thens
725718 return (False, IfStatement val' thens' Nothing)
726719checkIfStatement mass ret (IfStatement val thens (Just elses)) = do
727− val' <- check val Boolean
720+ val' <- check val tyBoolean
728721 (allCodePathsReturn1, _, thens') <- checkBlock mass ret thens
729722 (allCodePathsReturn2, elses') <- checkElseStatement mass ret elses
730723 return (allCodePathsReturn1 && allCodePathsReturn2, IfStatement val' thens' (Just elses'))
@@ -792,31 +785,30 @@ check' val (ConstrainedType constraints ty) = do
792785 TypeClassDictionaryInScope name className instanceTy Nothing TCDRegular) (map (Qualified Nothing) dictNames)
793786 (qualifyAllUnqualifiedNames moduleName env constraints)) $
794787 check val ty
795− return $ Abs dictNames val'
788+ return $ foldr Abs val' dictNames
796789check' val u@(TUnknown _) = do
797790 val'@(TypedValue _ _ ty) <- infer val
798791 -- Don't unify an unknown with an inferred polytype
799792 ty' <- replaceAllVarsWithUnknowns ty
800793 ty' ?= u
801794 return val'
802−check' v@(NumericLiteral _) Number = return v
803−check' v@(StringLiteral _) String = return v
804−check' v@(BooleanLiteral _) Boolean = return v
795+check' v@(NumericLiteral _) t | t == tyNumber = return v
796+check' v@(StringLiteral _) t | t == tyString = return v
797+check' v@(BooleanLiteral _) t | t == tyBoolean = return v
805798check' (Unary op val) ty = checkUnary op val ty
806799check' (Binary op left right) ty = checkBinary op left right ty
807−check' (ArrayLiteral vals) (TypeApp Array ty) = ArrayLiteral <$> forM vals (\val -> check val ty)
800+check' (ArrayLiteral vals) (TypeApp a ty) | a == tyArray = ArrayLiteral <$> forM vals (\val -> check val ty)
808801check' (Indexer index vals) ty = do
809− index' <- check index Number
810− vals' <- check vals (TypeApp Array ty)
802+ index' <- check index tyNumber
803+ vals' <- check vals (TypeApp tyArray ty)
811804 return $ Indexer index' vals'
812−check' (Abs args ret) (Function argTys retTy) = do
805+check' (Abs arg ret) (TypeApp (TypeApp t argTy) retTy) | t == tyFunction = do
813806 Just moduleName <- checkCurrentModule <$> get
814− guardWith "Incorrect number of function arguments" (length args == length argTys)
815− ret' <- bindLocalVariables moduleName (zip args argTys) $ check ret retTy
816− return $ Abs args ret'
817−check' (App f args) ret = do
807+ ret' <- bindLocalVariables moduleName [(arg, argTy)] $ check ret retTy
808+ return $ Abs arg ret'
809+check' (App f arg) ret = do
818810 f'@(TypedValue _ _ ft) <- infer f
819− app <- checkFunctionApplication f' ft args ret
811+ app <- checkFunctionApplication f' ft arg ret
820812 return $ app
821813check' v@(Var var) ty = do
822814 Just moduleName <- checkCurrentModule <$> get
@@ -842,7 +834,7 @@ check' (Case vals binders) ret = do
842834 binders' <- checkBinders ts ret binders
843835 return $ Case vals' binders'
844836check' (IfThenElse cond th el) ty = do
845− cond' <- check cond Boolean
837+ cond' <- check cond tyBoolean
846838 th' <- check th ty
847839 el' <- check el ty
848840 return $ IfThenElse cond' th' el'
@@ -918,42 +910,44 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
918910-- |
919911-- Check the type of a function application, rethrowing errors to provide a better error message
920912--
921−checkFunctionApplication :: Value -> Type -> [Value] -> Type -> UnifyT Check Value
922−checkFunctionApplication fn fnTy args ret = rethrow errorMessage $ checkFunctionApplication' fn fnTy args ret
913+checkFunctionApplication :: Value -> Type -> Value -> Type -> UnifyT Check Value
914+checkFunctionApplication fn fnTy arg ret = rethrow errorMessage $ checkFunctionApplication' fn fnTy arg ret
923915 where
924916 errorMessage msg = "Error applying function of type "
925917 ++ prettyPrintType fnTy
926− ++ " to arguments " ++ intercalate ", " (map prettyPrintValue args)
918+ ++ " to argument " ++ prettyPrintValue arg
927919 ++ ":\n" ++ msg
928920
929921-- |
930922-- Check the type of a function application
931923--
932−checkFunctionApplication' :: Value -> Type -> [Value] -> Type -> UnifyT Check Value
933−checkFunctionApplication' fn (Function argTys retTy) args ret = do
934− guardWith "Incorrect number of function arguments" (length args == length argTys)
935− args' <- zipWithM check args argTys
924+checkFunctionApplication' :: Value -> Type -> Value -> Type -> UnifyT Check Value
925+checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg ret = do
926+ tyFunction' ?= tyFunction
927+ arg' <- check arg argTy
936928 _ <- subsumes Nothing retTy ret
937− return $ App fn args'
938−checkFunctionApplication' fn (ForAll ident ty) args ret = do
929+ return $ App fn arg'
930+checkFunctionApplication' fn (ForAll ident ty) arg ret = do
939931 replaced <- replaceVarWithUnknown ident ty
940− checkFunctionApplication fn replaced args ret
941−checkFunctionApplication' fn u@(TUnknown _) args ret = do
942− args' <- mapM (\arg -> infer arg >>= \(TypedValue _ v t) -> TypedValue True v <$> replaceAllVarsWithUnknowns t) args
943− let tys = map (\(TypedValue _ _ t) -> t) args'
944− u ?= Function tys ret
945− return $ App fn args'
946−checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) args ret = do
932+ checkFunctionApplication fn replaced arg ret
933+checkFunctionApplication' fn u@(TUnknown _) arg ret = do
934+ arg' <- do
935+ TypedValue _ v t <- infer arg
936+ TypedValue True v <$> replaceAllVarsWithUnknowns t
937+ let ty = (\(TypedValue _ _ t) -> t) arg'
938+ u ?= function ty ret
939+ return $ App fn arg'
940+checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg ret = do
947941 ty <- expandTypeSynonym name tyArgs
948− checkFunctionApplication fn ty args ret
949−checkFunctionApplication' fn (ConstrainedType constraints fnTy) args ret = do
942+ checkFunctionApplication fn ty arg ret
943+checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
950944 env <- getEnv
951945 dicts <- getTypeClassDictionaries
952946 Just moduleName <- checkCurrentModule <$> get
953− checkFunctionApplication' (App fn (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) fnTy args ret
954−checkFunctionApplication' _ fnTy args ret = throwError $ "Applying a function of type "
947+ checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) fnTy arg ret
948+checkFunctionApplication' _ fnTy arg ret = throwError $ "Applying a function of type "
955949 ++ prettyPrintType fnTy
956− ++ " to argument(s) " ++ intercalate ", " (map prettyPrintValue args)
950+ ++ " to argument(s) " ++ prettyPrintValue arg
957951 ++ " does not yield a value of type " ++ prettyPrintType ret ++ "."
958952
959953-- |
@@ -975,8 +969,8 @@ subsumes' :: Maybe Value -> Type -> Type -> UnifyT Check (Maybe Value)
975969subsumes' val (ForAll ident ty1) ty2 = do
976970 replaced <- replaceVarWithUnknown ident ty1
977971 subsumes val replaced ty2
978−subsumes' val (Function args1 ret1) (Function args2 ret2) = do
979− zipWithM_ (subsumes Nothing) args2 args1
972+subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
973+ subsumes Nothing arg2 arg1
980974 subsumes Nothing ret1 ret2
981975 return val
982976subsumes' (Just val) (ConstrainedType constraints ty1) ty2 = do
@@ -984,7 +978,7 @@ subsumes' (Just val) (ConstrainedType constraints ty1) ty2 = do
984978 dicts <- getTypeClassDictionaries
985979 Just moduleName <- checkCurrentModule <$> get
986980 _ <- subsumes' Nothing ty1 ty2
987− return . Just $ App val (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))
981+ return . Just $ foldl App val (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))
988982subsumes' val ty1 ty2 = do
989983 ty1 ?= ty2
990984 return val