@@ -1,10 +1,22 @@
11{-# OPTIONS_GHC -Wall #-}
2−module Reporting.Result where
2+module Reporting.Result
3+ ( Result(..)
4+ , ok
5+ , throw
6+ , accumulate
7+ , warn
8+ , from
9+ , mapError
10+ , format
11+ , answerToEither
12+ , oneToValue
13+ )
14+ where
315
416import Control.Monad.Except (Except, runExcept)
517
18+import qualified Data.Bag as Bag
619import qualified Reporting.Annotation as A
7−import qualified Reporting.Bag as Bag
820import qualified Reporting.Region as R
921
1022
@@ -41,12 +53,7 @@ ok value =
4153
4254throw :: (Monoid i) => R.Region -> e -> Result i w e a
4355throw region err =
44− Result mempty Bag.empty (Err (Bag.singleton (A.A region err)))
45−
46−
47−throwMany :: (Monoid i) => [A.Located e] -> Result i w e a
48−throwMany errors =
49− Result mempty Bag.empty (Err (Bag.fromList errors))
56+ Result mempty Bag.empty (Err (Bag.one (A.A region err)))
5057
5158
5259accumulate :: (Monoid i) => i -> a -> Result i w e a
@@ -56,7 +63,7 @@ accumulate info value =
5663
5764warn :: (Monoid i) => R.Region -> w -> a -> Result i w e a
5865warn region warning a =
59− Result mempty (Bag.singleton (A.A region warning)) (Ok a)
66+ Result mempty (Bag.one (A.A region warning)) (Ok a)
6067
6168
6269
@@ -70,7 +77,7 @@ from f except =
7077 ok answer
7178
7279 Left errors ->
73− throwMany (map (A.map f) errors)
80+ Result mempty Bag.empty (Err (Bag.fromList (A.map f) errors))
7481
7582
7683mapError :: (e -> e') -> Result i w e a -> Result i w e' a
@@ -96,7 +103,7 @@ answerToEither onErr onOk answer =
96103 Right (onOk value)
97104
98105 Err errors ->
99− Left (Bag.toList onErr errors)
106+ Left (map onErr (Bag.toList errors))
100107
101108
102109oneToValue :: b -> (a -> b) -> One a -> b