1{-# OPTIONS_GHC -Wall #-}
16import Control.Monad.Except (Except, runExcept)
18import qualified Data.Bag as Bag
19import qualified Reporting.Annotation as A
20import qualified Reporting.Region as R
27data Result info warning error result =
30 , _warnings :: LBag warning
31 , _answer :: Answer (LBag error) result
35data Answer e a = Ok a | Err e
42data One a = None | One a
49ok :: (Monoid i) => a -> Result i w e a
51 Result mempty Bag.empty (Ok value)
54throw :: (Monoid i) => R.Region -> e -> Result i w e a
56 Result mempty Bag.empty (Err (Bag.one (A.A region err)))
59accumulate :: (Monoid i) => i -> a -> Result i w e a
60accumulate info value =
61 Result info Bag.empty (Ok value)
64warn :: (Monoid i) => R.Region -> w -> a -> Result i w e a
65warn region warning a =
66 Result mempty (Bag.one (A.A region warning)) (Ok a)
73from :: (Monoid i) => (e -> e') -> Except [A.Located e] a -> Result i w e' a
75 case runExcept except of
80 Result mempty Bag.empty (Err (Bag.fromList (A.map f) errors))
83mapError :: (e -> e') -> Result i w e a -> Result i w e' a
84mapError f (Result info warnings rawResult) =
85 Result info warnings $
91 Err (Bag.map (A.map f) msgs)
94format :: (Monoid i) => (e -> e') -> Result () w e a -> Result i w e' a
95format func (Result _ warnings answer) =
96 mapError func (Result mempty warnings answer)
99answerToEither :: (A.Located e -> e') -> (a -> a') -> Answer (LBag e) a -> Either [e'] a'
100answerToEither onErr onOk answer =
106 Left (map onErr (Bag.toList errors))
109oneToValue :: b -> (a -> b) -> One a -> b
110oneToValue fallback onOne one =
120-- EXTRA FANCY HELPERS
123instance Functor (Result i w e) where
124 fmap func (Result info warnings rawResult) =
127 Result info warnings (Ok (func a))
130 Result info warnings (Err msgs)
133instance (Monoid i) => Applicative (Result i w e) where
137 (<*>) (Result info warnings resultFunc) (Result info' warnings' resultVal) =
138 Result (mappend info info') (Bag.append warnings warnings') $
139 case (resultFunc, resultVal) of
143 (Err msgs, Err msgs') ->
144 Err (Bag.append msgs msgs')
153instance (Monoid i) => Monad (Result i w e) where
157 (>>=) (Result info warnings rawResult) callback =
160 Result info warnings (Err msg)
164 (Result info' warnings' rawResult') =
169 (Bag.append warnings warnings')
173instance Monoid (One a) where
178 case (left, right) of
186 error "There should only be one!"
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