1module Reporting.Result where
3import Control.Applicative ((<|>))
4import qualified Control.Monad as M
5import Control.Monad.Except (Except, runExcept)
7import qualified Reporting.Annotation as A
8import qualified Reporting.Region as R
9import qualified Reporting.PrettyPrint as P
14data Result warning error result =
16 (Maybe P.Dealiaser, [A.Located warning])
17 (RawResult [A.Located error] result)
27ok :: a -> Result w e a
29 Result (Nothing, []) (Ok value)
32throw :: R.Region -> e -> Result w e a
34 Result (Nothing, []) (Err [A.A region err])
37throwMany :: [A.Located e] -> Result w e a
39 Result (Nothing, []) (Err errors)
42from :: (e -> e') -> Except [A.Located e] a -> Result w e' a
44 case runExcept except of
49 throwMany (map (A.map f) errors)
52mapError :: (e -> e') -> Result w e a -> Result w e' a
53mapError f (Result warnings rawResult) =
60 Err (map (A.map f) msgs)
63warn :: R.Region -> w -> Result w e ()
65 Result (Nothing, [A.A region warning]) (Ok ())
68addWarnings :: [A.Located w] -> Result w e a -> Result w e a
69addWarnings newWarnings (Result (dealiaser, warnings) rawResult) =
70 Result (dealiaser, newWarnings ++ warnings) rawResult
73addDealiaser :: P.Dealiaser -> Result w e a -> Result w e a
74addDealiaser dealiaser (Result (_, warnings) rawResult) =
75 Result (Just dealiaser, warnings) rawResult
78destruct :: (e -> b) -> (a -> b) -> RawResult e a -> b
79destruct errFunc okFunc rawResult =
90instance M.Functor (Result w e) where
91 fmap func (Result warnings rawResult) =
94 Result warnings (Ok (func a))
97 Result warnings (Err msgs)
100instance Applicative (Result w e) where
104 (<*>) (Result context resultFunc) (Result context' resultVal) =
105 Result (merge context context') $
106 case (resultFunc, resultVal) of
110 (Err msgs, Err msgs') ->
120instance M.Monad (Result w e) where
124 (>>=) (Result context rawResult) callback =
127 Result context (Err msg)
130 let (Result context' rawResult') = callback value
132 Result (merge context context') rawResult'
135merge :: (Maybe a, [b]) -> (Maybe a, [b]) -> (Maybe a, [b])
136merge (dealiaser, warnings) (dealiaser', warnings') =
137 ( dealiaser <|> dealiaser'
138 , warnings ++ warnings'
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list