Skip to content

Commit

Permalink
🧩 [consolidate]: Inline fromRight into 'successful'.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolyp committed Oct 7, 2023
1 parent c7e8bb0 commit b67f226
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/EvalBwd.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module EvalBwd where
import Prelude hiding (absurd)

import Bindings (Var, varAnon)
import Control.Monad.Except (class MonadError, runExcept)
import Control.Monad.Except (class MonadError)
import Data.Exists (mkExists, runExists)
import Data.Foldable (foldr)
import Data.FoldableWithIndex (foldrWithIndex)
Expand All @@ -26,7 +26,7 @@ import Lattice (Raw, bot, botOf, expand, (∨))
import Partial.Unsafe (unsafePartial)
import Trace (AppTrace(..), Trace(..), VarDef(..)) as T
import Trace (AppTrace, ForeignTrace'(..), Match(..), Trace)
import Util (type (×), Endo, absurd, definitely', error, fromRight, nonEmpty, successful, (!), (×))
import Util (type (×), Endo, absurd, definitely', error, nonEmpty, successful, (!), (×))
import Util.Pair (zip) as P
import Val (Fun(..), Val(..)) as V
import Val (class Ann, DictRep(..), Env, ForeignOp, ForeignOp'(..), MatrixRep(..), Val, append_inv, (<+>))
Expand Down
11 changes: 4 additions & 7 deletions src/Util.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude hiding (absurd)

import Control.Apply (lift2)
import Control.Monad.Error.Class (class MonadError, class MonadThrow, catchError, throwError)
import Control.Monad.Except (Except, ExceptT(..), runExcept)
import Control.Monad.Except (Except, ExceptT, runExcept)
import Control.MonadPlus (class Alternative, guard)
import Data.Array ((!!), updateAt)
import Data.Bifunctor (bimap)
Expand All @@ -15,7 +15,6 @@ import Data.List.NonEmpty (NonEmptyList(..))
import Data.Map (Map)
import Data.Map (lookup, unionWith) as M
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Data.NonEmpty ((:|))
import Data.Profunctor.Strong ((&&&), (***))
import Data.Tuple (Tuple(..), fst, snd)
Expand Down Expand Up @@ -73,15 +72,13 @@ orElse :: forall a m. MonadThrow Error m => String -> Maybe a -> m a
orElse s Nothing = throw s
orElse _ (Just x) = pure x

fromRight :: forall a. Error + a -> a
fromRight (Right x) = x
fromRight (Left e) = error $ show e

mapLeft :: forall a b c. (a -> c) -> Either a b -> Either c b
mapLeft = flip bimap identity

successful :: forall a. MayFail a -> a
successful = runExcept >>> fromRight
successful = runExcept >>> case _ of
Right x -> x
Left e -> error $ show e

successfulWith :: String -> forall a. MayFail a -> a
successfulWith msg = successful <<< with msg
Expand Down

0 comments on commit b67f226

Please sign in to comment.