@@ -14,7 +14,6 @@
14-----------------------------------------------------------------------------
14-----------------------------------------------------------------------------
16{-# OPTIONS_GHC -fno-warn-orphans #-}
16{-# OPTIONS_GHC -fno-warn-orphans #-}
17−{-# LANGUAGE FlexibleInstances #-}
18{-# LANGUAGE FlexibleContexts #-}
17{-# LANGUAGE FlexibleContexts #-}
19{-# LANGUAGE MultiParamTypeClasses #-}
18{-# LANGUAGE MultiParamTypeClasses #-}
@@ -71,7 +70,6 @@ import Control.Arrow (Arrow(..))
71import qualified Data.Map as M
70import qualified Data.Map as M
72import Data.Function (on)
71import Data.Function (on)
73import Data.Ord (comparing)
72import Data.Ord (comparing)
74−import Data.Monoid ((<>))
76instance Partial Type where
74instance Partial Type where
77 unknown = TUnknown
75 unknown = TUnknown
@@ -85,7 +83,7 @@ instance Unifiable Check Type where
85-- Unify two types, updating the current substitution
83-- Unify two types, updating the current substitution
87unifyTypes :: Type -> Type -> UnifyT Type Check ()
85unifyTypes :: Type -> Type -> UnifyT Type Check ()
88−unifyTypes t1 t2 = rethrow (mkUnifyErrorStack ("Error unifying type " ++ prettyPrintType t1 ++ " with type " ++ prettyPrintType t2) Nothing <>) $
86+unifyTypes t1 t2 = rethrow (\e -> "Error unifying type " ++ prettyPrintType t1 ++ " with type " ++ prettyPrintType t2 ++ ":\n" ++ e) $
89 unifyTypes' t1 t2
87 unifyTypes' t1 t2
91 unifyTypes' (TUnknown u1) (TUnknown u2) | u1 == u2 = return ()
89 unifyTypes' (TUnknown u1) (TUnknown u2) | u1 == u2 = return ()
@@ -102,16 +100,16 @@ unifyTypes t1 t2 = rethrow (mkUnifyErrorStack ("Error unifying type " ++ prettyP
102 let sk1 = skolemize ident1 sko sc1' ty1
100 let sk1 = skolemize ident1 sko sc1' ty1
103 let sk2 = skolemize ident2 sko sc2' ty2
101 let sk2 = skolemize ident2 sko sc2' ty2
104 sk1 `unifyTypes` sk2
102 sk1 `unifyTypes` sk2
105− _ -> error "Skolemized type variable was not given a scope"
103+ _ -> throwError (prettyPrintType ty1)
106 unifyTypes' (ForAll ident ty1 (Just sc)) ty2 = do
104 unifyTypes' (ForAll ident ty1 (Just sc)) ty2 = do
107 sko <- newSkolemConstant
105 sko <- newSkolemConstant
108 let sk = skolemize ident sko sc ty1
106 let sk = skolemize ident sko sc ty1
109 sk `unifyTypes` ty2
107 sk `unifyTypes` ty2
110− unifyTypes' ForAll{} _ = throwError . strMsg $ "Skolem variable scope is unspecified"
108+ unifyTypes' ForAll{} _ = throwError "Skolem variable scope is unspecified"
111 unifyTypes' ty f@ForAll{} = f `unifyTypes` ty
109 unifyTypes' ty f@ForAll{} = f `unifyTypes` ty
112 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
110 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
113 unifyTypes' (TypeConstructor c1) (TypeConstructor c2) =
111 unifyTypes' (TypeConstructor c1) (TypeConstructor c2) =
114− guardWith (strMsg ("Cannot unify " ++ show c1 ++ " with " ++ show c2 ++ ".")) (c1 == c2)
112+ guardWith ("Cannot unify " ++ show c1 ++ " with " ++ show c2 ++ ".") (c1 == c2)
115 unifyTypes' (TypeApp t3 t4) (TypeApp t5 t6) = do
113 unifyTypes' (TypeApp t3 t4) (TypeApp t5 t6) = do
116 t3 `unifyTypes` t5
114 t3 `unifyTypes` t5
117 t4 `unifyTypes` t6
115 t4 `unifyTypes` t6
@@ -120,9 +118,10 @@ unifyTypes t1 t2 = rethrow (mkUnifyErrorStack ("Error unifying type " ++ prettyP
120 unifyTypes' r1 r2@RCons{} = unifyRows r1 r2
118 unifyTypes' r1 r2@RCons{} = unifyRows r1 r2
121 unifyTypes' r1@REmpty r2 = unifyRows r1 r2
119 unifyTypes' r1@REmpty r2 = unifyRows r1 r2
122 unifyTypes' r1 r2@REmpty = unifyRows r1 r2
120 unifyTypes' r1 r2@REmpty = unifyRows r1 r2
123− unifyTypes' t@(ConstrainedType _ _) _ = throwError . strMsg $ "Attempted to unify a constrained type " ++ prettyPrintType t ++ " with another type."
121+ unifyTypes' t@(ConstrainedType _ _) _ = throwError $ "Attempted to unify a constrained type " ++ prettyPrintType t ++
122+ " with another type."
124 unifyTypes' t3 t4@(ConstrainedType _ _) = unifyTypes' t4 t3
123 unifyTypes' t3 t4@(ConstrainedType _ _) = unifyTypes' t4 t3
125− unifyTypes' t3 t4 = throwError . strMsg $ "Cannot unify " ++ prettyPrintType t3 ++ " with " ++ prettyPrintType t4 ++ "."
124+ unifyTypes' t3 t4 = throwError $ "Cannot unify " ++ prettyPrintType t3 ++ " with " ++ prettyPrintType t4 ++ "."
128-- Unify two rows, updating the current substitution
127-- Unify two rows, updating the current substitution
@@ -155,7 +154,7 @@ unifyRows r1 r2 =
155 unifyRows' [] REmpty [] REmpty = return ()
154 unifyRows' [] REmpty [] REmpty = return ()
156 unifyRows' [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = return ()
155 unifyRows' [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = return ()
157 unifyRows' [] (Skolem s1 _) [] (Skolem s2 _) | s1 == s2 = return ()
156 unifyRows' [] (Skolem s1 _) [] (Skolem s2 _) | s1 == s2 = return ()
158− unifyRows' sd3 r3 sd4 r4 = throwError . strMsg $ "Cannot unify (" ++ prettyPrintRow (rowFromList (sd3, r3)) ++ ") with (" ++ prettyPrintRow (rowFromList (sd4, r4)) ++ ")"
157+ unifyRows' sd3 r3 sd4 r4 = throwError $ "Cannot unify (" ++ prettyPrintRow (rowFromList (sd3, r3)) ++ ") with (" ++ prettyPrintRow (rowFromList (sd4, r4)) ++ ")."
161-- Infer the types of multiple mutually-recursive values, and return elaborated values including
160-- Infer the types of multiple mutually-recursive values, and return elaborated values including
@@ -218,7 +217,7 @@ typeForBindingGroupElement moduleName e@(_, (val, _)) dict untypedDict = do
218 (ident, (val', Just (ty, checkType))) -> do
217 (ident, (val', Just (ty, checkType))) -> do
219 -- Kind check
218 -- Kind check
220 kind <- liftCheck $ kindOf moduleName ty
219 kind <- liftCheck $ kindOf moduleName ty
221− guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
220+ guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
222 -- Check the type with the new names in scope
221 -- Check the type with the new names in scope
223 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
222 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
224 val'' <- bindNames dict' $ if checkType
223 val'' <- bindNames dict' $ if checkType
@@ -271,7 +270,7 @@ replaceTypeClassDictionaries mn = everywhereM' (mkM go)
271entails :: Environment -> ModuleName -> [TypeClassDictionaryInScope] -> (Qualified ProperName, [Type]) -> Check Value
270entails :: Environment -> ModuleName -> [TypeClassDictionaryInScope] -> (Qualified ProperName, [Type]) -> Check Value
272entails env moduleName context goal@(className, tys) = do
271entails env moduleName context goal@(className, tys) = do
273 case go goal of
272 case go goal of
274− [] -> throwError . strMsg $ "No " ++ show className ++ " instance found for " ++ intercalate ", " (map prettyPrintType tys)
273+ [] -> throwError $ "No " ++ show className ++ " instance found for " ++ intercalate ", " (map prettyPrintType tys)
275 (dict : _) -> return dict
274 (dict : _) -> return dict
277 go (className', tys') =
276 go (className', tys') =
@@ -363,7 +362,7 @@ skolemEscapeCheck root@TypedValue{} =
363 -- an escaped skolem variable.
362 -- an escaped skolem variable.
364 case everythingWithContext [] (++) (mkQ ((,) []) go) root of
363 case everythingWithContext [] (++) (mkQ ((,) []) go) root of
365 [] -> return ()
364 [] -> return ()
366− ((binding, val) : _) -> throwError $ mkUnifyErrorStack ("Rigid/skolem type variable " ++ maybe "" (("bound by " ++) . prettyPrintValue) binding ++ " has escaped.") (Just (ValueError val))
365+ ((binding, val) : _) -> throwError $ "Rigid/skolem type variable bound by " ++ maybe "<unknown>" prettyPrintValue binding ++ " has escaped at " ++ prettyPrintValue val
368 go :: Value -> [(SkolemScope, Value)] -> ([(Maybe Value, Value)], [(SkolemScope, Value)])
367 go :: Value -> [(SkolemScope, Value)] -> ([(Maybe Value, Value)], [(SkolemScope, Value)])
369 go val@(TypedValue _ _ (ForAll _ _ (Just sco))) scos = ([], (sco, val) : scos)
368 go val@(TypedValue _ _ (ForAll _ _ (Just sco))) scos = ([], (sco, val) : scos)
@@ -382,7 +381,7 @@ skolemEscapeCheck root@TypedValue{} =
383 go' val@(TypedValue _ _ (ForAll _ _ (Just sco'))) | sco == sco' = Just val
382 go' val@(TypedValue _ _ (ForAll _ _ (Just sco'))) | sco == sco' = Just val
384 go' _ = Nothing
383 go' _ = Nothing
385−skolemEscapeCheck val = throwError $ mkUnifyErrorStack "Untyped value passed to skolemEscapeCheck" (Just (ValueError val))
384+skolemEscapeCheck val = throwError $ "Untyped value passed to skolemEscapeCheck: " ++ prettyPrintValue val
388-- Ensure a row contains no duplicate labels
387-- Ensure a row contains no duplicate labels
@@ -445,10 +444,10 @@ replaceAllTypeSynonyms' env d =
446 saturateAllTypeSynonyms syns d
445 saturateAllTypeSynonyms syns d
448−replaceAllTypeSynonyms :: (Error e, Functor m, Monad m, MonadState CheckState m, MonadError e m) => (D.Data d) => d -> m d
447+replaceAllTypeSynonyms :: (Functor m, Monad m, MonadState CheckState m, MonadError String m) => (D.Data d) => d -> m d
449replaceAllTypeSynonyms d = do
448replaceAllTypeSynonyms d = do
450 env <- getEnv
449 env <- getEnv
451− either (throwError . strMsg) return $ replaceAllTypeSynonyms' env d
450+ either throwError return $ replaceAllTypeSynonyms' env d
454-- \"Desaturate\" @SaturatedTypeSynonym@s
453-- \"Desaturate\" @SaturatedTypeSynonym@s
@@ -470,12 +469,12 @@ expandTypeSynonym' env name args =
470 replaceAllTypeSynonyms' env repl
469 replaceAllTypeSynonyms' env repl
471 Nothing -> error "Type synonym was not defined"
470 Nothing -> error "Type synonym was not defined"
473−expandTypeSynonym :: (Error e, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Qualified ProperName -> [Type] -> m Type
472+expandTypeSynonym :: (Functor m, Monad m, MonadState CheckState m, MonadError String m) => Qualified ProperName -> [Type] -> m Type
474expandTypeSynonym name args = do
473expandTypeSynonym name args = do
475 env <- getEnv
474 env <- getEnv
476− either (throwError . strMsg) return $ expandTypeSynonym' env name args
475+ either throwError return $ expandTypeSynonym' env name args
478−expandAllTypeSynonyms :: (Error e, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
477+expandAllTypeSynonyms :: (Functor m, Monad m, MonadState CheckState m, MonadError String m) => Type -> m Type
479expandAllTypeSynonyms = everywhereM' (mkM go)
478expandAllTypeSynonyms = everywhereM' (mkM go)
481 go (SaturatedTypeSynonym name args) = expandTypeSynonym name args
480 go (SaturatedTypeSynonym name args) = expandTypeSynonym name args
@@ -484,14 +483,14 @@ expandAllTypeSynonyms = everywhereM' (mkM go)
485-- Ensure a set of property names and value does not contain duplicate labels
484-- Ensure a set of property names and value does not contain duplicate labels
487−ensureNoDuplicateProperties :: (Error e, MonadError e m) => [(String, Value)] -> m ()
486+ensureNoDuplicateProperties :: (MonadError String m) => [(String, Value)] -> m ()
488−ensureNoDuplicateProperties ps = guardWith (strMsg "Duplicate property names") $ length (nub . map fst $ ps) == length ps
487+ensureNoDuplicateProperties ps = guardWith "Duplicate property names" $ length (nub . map fst $ ps) == length ps
491-- Infer a type for a value, rethrowing any error to provide a more useful error message
490-- Infer a type for a value, rethrowing any error to provide a more useful error message
493infer :: Value -> UnifyT Type Check Value
492infer :: Value -> UnifyT Type Check Value
494−infer val = rethrow (mkUnifyErrorStack "Error inferring type of value" (Just (ValueError val)) <>) $ infer' val
493+infer val = rethrow (\e -> "Error inferring type of term " ++ prettyPrintValue val ++ ":\n" ++ e) $ infer' val
497-- Infer a type for a value
496-- Infer a type for a value
@@ -552,7 +551,7 @@ infer' (Var var) = do
552infer' v@(Constructor c) = do
551infer' v@(Constructor c) = do
553 env <- getEnv
552 env <- getEnv
554 case M.lookup c (dataConstructors env) of
553 case M.lookup c (dataConstructors env) of
555− Nothing -> throwError . strMsg $ "Constructor " ++ show c ++ " is undefined"
554+ Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
556 Just (_, ty) -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
555 Just (_, ty) -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
557 return $ TypedValue True v ty'
556 return $ TypedValue True v ty'
558infer' (Case vals binders) = do
557infer' (Case vals binders) = do
@@ -572,7 +571,7 @@ infer' (Let ds val) = do
572infer' (TypedValue checkType val ty) = do
571infer' (TypedValue checkType val ty) = do
573 Just moduleName <- checkCurrentModule <$> get
572 Just moduleName <- checkCurrentModule <$> get
574 kind <- liftCheck $ kindOf moduleName ty
573 kind <- liftCheck $ kindOf moduleName ty
575− guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
574+ guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
576 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
575 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
577 val' <- if checkType then check val ty' else return val
576 val' <- if checkType then check val ty' else return val
578 return $ TypedValue True val' ty'
577 return $ TypedValue True val' ty'
@@ -632,8 +631,8 @@ inferBinder val (ConstructorBinder ctor binders) = do
632 return M.empty
631 return M.empty
633 go (binder : binders') (TypeApp (TypeApp t obj) ret) | t == tyFunction =
632 go (binder : binders') (TypeApp (TypeApp t obj) ret) | t == tyFunction =
634 M.union <$> inferBinder obj binder <*> go binders' ret
633 M.union <$> inferBinder obj binder <*> go binders' ret
635− go _ _ = throwError . strMsg $ "Wrong number of arguments to constructor " ++ show ctor
634+ go _ _ = throwError $ "Wrong number of arguments to constructor " ++ show ctor
636− _ -> throwError . strMsg $ "Constructor " ++ show ctor ++ " is not defined"
635+ _ -> throwError $ "Constructor " ++ show ctor ++ " is not defined"
637inferBinder val (ObjectBinder props) = do
636inferBinder val (ObjectBinder props) = do
638 row <- fresh
637 row <- fresh
639 rest <- fresh
638 rest <- fresh
@@ -712,13 +711,15 @@ introduceSkolemScope = everywhereM (mkM go)
712-- Check the type of a value, rethrowing errors to provide a better error message
711-- Check the type of a value, rethrowing errors to provide a better error message
714check :: Value -> Type -> UnifyT Type Check Value
713check :: Value -> Type -> UnifyT Type Check Value
715−check val ty = rethrow (mkUnifyErrorStack errorMessage (Just (ValueError val)) <>) $ check' val ty
714+check val ty = rethrow errorMessage $ check' val ty
717− errorMessage =
716+ errorMessage msg =
718 "Error checking type of term " ++
717 "Error checking type of term " ++
719 prettyPrintValue val ++
718 prettyPrintValue val ++
720 " against type " ++
719 " against type " ++
721− prettyPrintType ty
720+ prettyPrintType ty ++
724-- Check the type of a value
725-- Check the type of a value
@@ -772,16 +773,16 @@ check' v@(Var var) ty = do
772 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
773 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
773 v' <- subsumes (Just v) repl ty'
774 v' <- subsumes (Just v) repl ty'
774 case v' of
775 case v' of
775− Nothing -> throwError . strMsg $ "Unable to check type subsumption"
776+ Nothing -> throwError "Unable to check type subsumption"
776 Just v'' -> return $ TypedValue True v'' ty'
777 Just v'' -> return $ TypedValue True v'' ty'
777check' (TypedValue checkType val ty1) ty2 = do
778check' (TypedValue checkType val ty1) ty2 = do
778 Just moduleName <- checkCurrentModule <$> get
779 Just moduleName <- checkCurrentModule <$> get
779 kind <- liftCheck $ kindOf moduleName ty1
780 kind <- liftCheck $ kindOf moduleName ty1
780− guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
781+ guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
781 ty1' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
782 ty1' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
782 val' <- subsumes (Just val) ty1' ty2
783 val' <- subsumes (Just val) ty1' ty2
783 case val' of
784 case val' of
784− Nothing -> throwError . strMsg $ "Unable to check type subsumption"
785+ Nothing -> throwError "Unable to check type subsumption"
785 Just val'' -> do
786 Just val'' -> do
786 val''' <- if checkType then check val'' ty1' else return val''
787 val''' <- if checkType then check val'' ty1' else return val''
787 return $ TypedValue checkType (TypedValue True val''' ty1) ty2
788 return $ TypedValue checkType (TypedValue True val''' ty1) ty2
@@ -815,7 +816,7 @@ check' (Accessor prop val) ty = do
815check' (Constructor c) ty = do
816check' (Constructor c) ty = do
816 env <- getEnv
817 env <- getEnv
817 case M.lookup c (dataConstructors env) of
818 case M.lookup c (dataConstructors env) of
818− Nothing -> throwError . strMsg $ "Constructor " ++ show c ++ " is undefined"
819+ Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
819 Just (_, ty1) -> do
820 Just (_, ty1) -> do
820 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
821 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
821 _ <- subsumes Nothing repl ty
822 _ <- subsumes Nothing repl ty
@@ -826,7 +827,7 @@ check' (Let ds val) ty = do
826check' val ty | containsTypeSynonyms ty = do
827check' val ty | containsTypeSynonyms ty = do
827 ty' <- introduceSkolemScope <=< expandAllTypeSynonyms $ ty
828 ty' <- introduceSkolemScope <=< expandAllTypeSynonyms $ ty
828 check val ty'
829 check val ty'
829−check' val ty = throwError $ mkUnifyErrorStack ("Value does not have type " ++ prettyPrintType ty) (Just (ValueError val))
830+check' val ty = throwError $ prettyPrintValue val ++ " does not have type " ++ prettyPrintType ty
831containsTypeSynonyms :: Type -> Bool
832containsTypeSynonyms :: Type -> Bool
832containsTypeSynonyms = everything (||) (mkQ False go) where
833containsTypeSynonyms = everything (||) (mkQ False go) where
@@ -845,8 +846,8 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
845 return []
846 return []
846 go [] [] (Skolem _ _) | lax = return []
847 go [] [] (Skolem _ _) | lax = return []
847 go [] ((p, _): _) _ | lax = return []
848 go [] ((p, _): _) _ | lax = return []
848− | otherwise = throwError $ mkUnifyErrorStack ("Object does not have property " ++ p) (Just (ValueError (ObjectLiteral ps)))
849+ | otherwise = throwError $ prettyPrintValue (ObjectLiteral ps) ++ " does not have property " ++ p
849− go ((p,_):_) [] REmpty = throwError $ mkUnifyErrorStack ("Property " ++ p ++ " is not present in closed object type " ++ prettyPrintRow row) (Just (ValueError (ObjectLiteral ps)))
850+ go ((p,_):_) [] REmpty = throwError $ "Property " ++ p ++ " is not present in closed object type " ++ prettyPrintRow row
850 go ((p,v):ps') [] u@(TUnknown _) = do
851 go ((p,v):ps') [] u@(TUnknown _) = do
851 v'@(TypedValue _ _ ty) <- infer v
852 v'@(TypedValue _ _ ty) <- infer v
852 rest <- fresh
853 rest <- fresh
@@ -865,17 +866,18 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
865 v' <- check v ty
866 v' <- check v ty
866 ps'' <- go ps' (delete (p, ty) ts) r
867 ps'' <- go ps' (delete (p, ty) ts) r
867 return $ (p, v') : ps''
868 return $ (p, v') : ps''
868− go _ _ _ = throwError $ mkUnifyErrorStack ("Object does not have type " ++ prettyPrintType (TypeApp tyObject row)) (Just (ValueError (ObjectLiteral ps)))
869+ go _ _ _ = throwError $ prettyPrintValue (ObjectLiteral ps) ++ " does not have type " ++ prettyPrintType (TypeApp tyObject row)
871-- Check the type of a function application, rethrowing errors to provide a better error message
872-- Check the type of a function application, rethrowing errors to provide a better error message
873checkFunctionApplication :: Value -> Type -> Value -> Maybe Type -> UnifyT Type Check (Type, Value)
874checkFunctionApplication :: Value -> Type -> Value -> Maybe Type -> UnifyT Type Check (Type, Value)
874−checkFunctionApplication fn fnTy arg ret = rethrow (mkUnifyErrorStack errorMessage (Just (ValueError fn)) <>) $ checkFunctionApplication' fn fnTy arg ret
875+checkFunctionApplication fn fnTy arg ret = rethrow errorMessage $ checkFunctionApplication' fn fnTy arg ret
876− errorMessage = "Error applying function of type "
877+ errorMessage msg = "Error applying function of type "
877 ++ prettyPrintType fnTy
878 ++ prettyPrintType fnTy
878 ++ " to argument " ++ prettyPrintValue arg
879 ++ " to argument " ++ prettyPrintValue arg
881-- Check the type of a function application
883-- Check the type of a function application
@@ -905,7 +907,7 @@ checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg ret = do
905checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
907checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
906 dicts <- getTypeClassDictionaries
908 dicts <- getTypeClassDictionaries
907 checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) constraints)) fnTy arg ret
909 checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) constraints)) fnTy arg ret
908−checkFunctionApplication' _ fnTy arg _ = throwError . strMsg $ "Cannot apply a function of type "
910+checkFunctionApplication' _ fnTy arg _ = throwError $ "Cannot apply a function of type "
909 ++ prettyPrintType fnTy
911 ++ prettyPrintType fnTy
910 ++ " to argument " ++ prettyPrintValue arg
912 ++ " to argument " ++ prettyPrintValue arg
@@ -913,12 +915,13 @@ checkFunctionApplication' _ fnTy arg _ = throwError . strMsg $ "Cannot apply a f
913-- Check whether one type subsumes another, rethrowing errors to provide a better error message
915-- Check whether one type subsumes another, rethrowing errors to provide a better error message
915subsumes :: Maybe Value -> Type -> Type -> UnifyT Type Check (Maybe Value)
917subsumes :: Maybe Value -> Type -> Type -> UnifyT Type Check (Maybe Value)
916−subsumes val ty1 ty2 = rethrow (mkUnifyErrorStack errorMessage (ValueError <$> val) <>) $ subsumes' val ty1 ty2
918+subsumes val ty1 ty2 = rethrow errorMessage $ subsumes' val ty1 ty2
918− errorMessage = "Error checking that type "
920+ errorMessage msg = "Error checking that type "
919 ++ prettyPrintType ty1
921 ++ prettyPrintType ty1
920 ++ " subsumes type "
922 ++ " subsumes type "
921 ++ prettyPrintType ty2
923 ++ prettyPrintType ty2
924-- Check whether one type subsumes another
927-- Check whether one type subsumes another
@@ -933,7 +936,7 @@ subsumes' val ty1 (ForAll ident ty2 sco) =
933 sko <- newSkolemConstant
936 sko <- newSkolemConstant
934 let sk = skolemize ident sko sco' ty2
937 let sk = skolemize ident sko sco' ty2
935 subsumes val ty1 sk
938 subsumes val ty1 sk
936− Nothing -> throwError . strMsg $ "Skolem variable scope is unspecified"
939+ Nothing -> throwError "Skolem variable scope is unspecified"
937subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
940subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
938 _ <- subsumes Nothing arg2 arg1
941 _ <- subsumes Nothing arg2 arg1
939 _ <- subsumes Nothing ret1 ret2
942 _ <- subsumes Nothing ret1 ret2
@@ -973,4 +976,3 @@ subsumes' val ty1 ty2 = do
973 ty1 =?= ty2
976 ty1 =?= ty2
974 return val
977 return val