@@ -24,8 +24,8 @@ import Language.PureScript.Names
24import Language.PureScript.Declarations
24import Language.PureScript.Declarations
25import Language.PureScript.Environment
25import Language.PureScript.Environment
26import Language.PureScript.TypeClassDictionaries
26import Language.PureScript.TypeClassDictionaries
27−import Language.PureScript.Pretty
28import Language.PureScript.Options
27import Language.PureScript.Options
28+import Language.PureScript.Errors
30import Data.Maybe
30import Data.Maybe
31import Data.Monoid
31import Data.Monoid
@@ -36,78 +36,6 @@ import Control.Monad.Error
36import Control.Monad.Unify
36import Control.Monad.Unify
38import qualified Data.Map as M
38import qualified Data.Map as M
39−import Data.List (intercalate)
42−-- Type for sources of type checking errors
46− -- An error which originated at a Value
50− -- An error which originated at a Type
52− | TypeError Type deriving (Show)
57−data UnifyError = UnifyError {
61− unifyErrorMessage :: String
63− -- The value where the error occurred
65− , unifyErrorValue :: Maybe UnifyErrorSource
67− -- Optional source position information
69− , unifyErrorPosition :: Maybe SourcePos
73−-- A stack trace for an error
75−newtype UnifyErrorStack = UnifyErrorStack { runUnifyErrorStack :: [UnifyError] } deriving (Show, Monoid)
77−instance Error UnifyErrorStack where
78− strMsg s = UnifyErrorStack [UnifyError s Nothing Nothing]
79− noMsg = UnifyErrorStack []
81−prettyPrintUnifyErrorStack :: Options -> UnifyErrorStack -> String
82−prettyPrintUnifyErrorStack opts (UnifyErrorStack es) =
83− case mconcat $ map (Last . unifyErrorPosition) es of
84− Last (Just sourcePos) -> "Error at " ++ show sourcePos ++ ": \n" ++ prettyPrintUnifyErrorStack'
85− _ -> prettyPrintUnifyErrorStack'
87− prettyPrintUnifyErrorStack' :: String
88− prettyPrintUnifyErrorStack'
89− | optionsVerboseErrors opts =
90− intercalate "\n" (map showError (filter isErrorNonEmpty es))
93− es' = filter isErrorNonEmpty es
94− in case length es' of
95− 1 -> showError (head es')
96− _ -> showError (head es') ++ "\n" ++ showError (last es')
98−isErrorNonEmpty :: UnifyError -> Bool
99−isErrorNonEmpty = not . null . unifyErrorMessage
101−showError :: UnifyError -> String
102−showError (UnifyError msg Nothing _) = msg
103−showError (UnifyError msg (Just (ValueError val)) _) = "Error in value " ++ prettyPrintValue val ++ "\n" ++ msg
104−showError (UnifyError msg (Just (TypeError ty)) _) = "Error in type " ++ prettyPrintType ty ++ "\n" ++ msg
106−mkUnifyErrorStack :: String -> Maybe UnifyErrorSource -> UnifyErrorStack
107−mkUnifyErrorStack msg t = UnifyErrorStack [UnifyError msg t Nothing]
109−positionError :: SourcePos -> UnifyErrorStack
110−positionError pos = UnifyErrorStack [UnifyError "" Nothing (Just pos)]
113-- Temporarily bind a collection of names to values
41-- Temporarily bind a collection of names to values