@@ -40,19 +40,19 @@ import Language.PureScript.Types
41-- Build a type substitution for a type synonym
41-- Build a type substitution for a type synonym
43−buildTypeSubstitution :: Qualified ProperName -> Int -> Type -> Either String (Maybe Type)
43+buildTypeSubstitution :: Qualified ProperName -> Int -> Type -> Either ErrorMessage (Maybe Type)
44buildTypeSubstitution name n = go n []
44buildTypeSubstitution name n = go n []
46− go :: Int -> [Type] -> Type -> Either String (Maybe Type)
46+ go :: Int -> [Type] -> Type -> Either ErrorMessage (Maybe Type)
47 go 0 args (TypeConstructor ctor) | name == ctor = return (Just $ SaturatedTypeSynonym ctor args)
47 go 0 args (TypeConstructor ctor) | name == ctor = return (Just $ SaturatedTypeSynonym ctor args)
48− go m _ (TypeConstructor ctor) | m > 0 && name == ctor = throwError $ "Partially applied type synonym " ++ show name
48+ go m _ (TypeConstructor ctor) | m > 0 && name == ctor = throwError $ PartiallyAppliedSynonym name
49 go m args (TypeApp f arg) = go (m - 1) (arg:args) f
49 go m args (TypeApp f arg) = go (m - 1) (arg:args) f
50 go _ _ _ = return Nothing
50 go _ _ _ = return Nothing
53-- Replace all instances of a specific type synonym with the @SaturatedTypeSynonym@ data constructor
53-- Replace all instances of a specific type synonym with the @SaturatedTypeSynonym@ data constructor
55−saturateTypeSynonym :: Qualified ProperName -> Int -> Type -> Either String Type
55+saturateTypeSynonym :: Qualified ProperName -> Int -> Type -> Either ErrorMessage Type
56saturateTypeSynonym name n = everywhereOnTypesTopDownM replace
56saturateTypeSynonym name n = everywhereOnTypesTopDownM replace
58 replace t = fromMaybe t <$> buildTypeSubstitution name n t
58 replace t = fromMaybe t <$> buildTypeSubstitution name n t
@@ -60,7 +60,7 @@ saturateTypeSynonym name n = everywhereOnTypesTopDownM replace
61-- Replace all type synonyms with the @SaturatedTypeSynonym@ data constructor
61-- Replace all type synonyms with the @SaturatedTypeSynonym@ data constructor
63−saturateAllTypeSynonyms :: [(Qualified ProperName, Int)] -> Type -> Either String Type
63+saturateAllTypeSynonyms :: [(Qualified ProperName, Int)] -> Type -> Either ErrorMessage Type
64saturateAllTypeSynonyms syns d = foldM (\result (name, n) -> saturateTypeSynonym name n result) d syns
64saturateAllTypeSynonyms syns d = foldM (\result (name, n) -> saturateTypeSynonym name n result) d syns
@@ -76,7 +76,7 @@ desaturateAllTypeSynonyms = everywhereOnTypes replaceSaturatedTypeSynonym
76-- Replace fully applied type synonyms with the @SaturatedTypeSynonym@ data constructor, which helps generate
76-- Replace fully applied type synonyms with the @SaturatedTypeSynonym@ data constructor, which helps generate
77-- better error messages during unification.
77-- better error messages during unification.
79−replaceAllTypeSynonyms' :: Environment -> Type -> Either String Type
79+replaceAllTypeSynonyms' :: Environment -> Type -> Either ErrorMessage Type
80replaceAllTypeSynonyms' env d =
80replaceAllTypeSynonyms' env d =
82 syns = map (\(name, (args, _)) -> (name, length args)) . M.toList $ typeSynonyms env
82 syns = map (\(name, (args, _)) -> (name, length args)) . M.toList $ typeSynonyms env
@@ -86,12 +86,12 @@ replaceAllTypeSynonyms' env d =
86replaceAllTypeSynonyms :: (e ~ MultipleErrors, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
86replaceAllTypeSynonyms :: (e ~ MultipleErrors, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
87replaceAllTypeSynonyms d = do
87replaceAllTypeSynonyms d = do
88 env <- getEnv
88 env <- getEnv
89− either (throwError . strMsg) return $ replaceAllTypeSynonyms' env d
89+ either (throwError . errorMessage) return $ replaceAllTypeSynonyms' env d
92-- Replace a type synonym and its arguments with the aliased type
92-- Replace a type synonym and its arguments with the aliased type
94−expandTypeSynonym' :: Environment -> Qualified ProperName -> [Type] -> Either String Type
94+expandTypeSynonym' :: Environment -> Qualified ProperName -> [Type] -> Either ErrorMessage Type
95expandTypeSynonym' env name args =
95expandTypeSynonym' env name args =
96 case M.lookup name (typeSynonyms env) of
96 case M.lookup name (typeSynonyms env) of
97 Just (synArgs, body) -> do
97 Just (synArgs, body) -> do
@@ -102,7 +102,7 @@ expandTypeSynonym' env name args =
102expandTypeSynonym :: (e ~ MultipleErrors, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Qualified ProperName -> [Type] -> m Type
102expandTypeSynonym :: (e ~ MultipleErrors, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Qualified ProperName -> [Type] -> m Type
103expandTypeSynonym name args = do
103expandTypeSynonym name args = do
104 env <- getEnv
104 env <- getEnv
105− either (throwError . strMsg) return $ expandTypeSynonym' env name args
105+ either (throwError . errorMessage) return $ expandTypeSynonym' env name args
107expandAllTypeSynonyms :: (e ~ MultipleErrors, Functor m, Applicative m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
107expandAllTypeSynonyms :: (e ~ MultipleErrors, Functor m, Applicative m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
108expandAllTypeSynonyms = everywhereOnTypesTopDownM go
108expandAllTypeSynonyms = everywhereOnTypesTopDownM go