{-# LANGUAGE FlexibleContexts #-}
module Data.Either.Located
  ( module Data.Either
  , fromRight, fromLeft
  ) where

import Data.Either
import qualified GHC.Err.Located as L

fromRight :: L.HasCallStack
          => Either a b -> b
fromRight (Right x) = x
fromRight (Left _)  = L.error "Either.fromRight: Left"

fromLeft :: L.HasCallStack
         => Either a b -> a
fromLeft (Left x)  = x
fromLeft (Right _) = L.error "Either.fromLeft: Right"

{-# LANGUAGE FlexibleContexts #-}
module Data.Either.Located
  ( module E
  , fromRight, fromLeft
  ) where

import qualified Data.Either as E
import qualified GHC.Err.Located as L

fromRight :: L.HasCallStack
          => Either a b -> b
fromRight (Right x) = x
fromRight (Left _)  = L.error "Either.fromRight: Left"

fromLeft :: L.HasCallStack
         => Either a b -> a
fromLeft (Left x)  = x
fromLeft (Right _) = L.error "Either.fromLeft: Right"

Use a qualified import for GHC 8.2 compatibility
Use a qualified import for GHC 8.2 compatibility

It looks like Data.Either exports its own fromLeft and fromRight as of the base
included in 8.2
