| Copyright | [2018] Trevor L. McDonell | 
|---|---|
| License | BSD3 | 
| Maintainer | Trevor L. McDonell <tmcdonell@cse.unsw.edu.au> | 
| Stability | experimental | 
| Portability | non-portable (GHC extensions) | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.Array.Accelerate.Data.Either
Contents
Description
Since: 1.2.0.0
Synopsis
- data Either a b
 - left :: forall a b. (Elt a, Elt b) => Exp a -> Exp (Either a b)
 - right :: forall a b. (Elt a, Elt b) => Exp b -> Exp (Either a b)
 - either :: (Elt a, Elt b, Elt c) => (Exp a -> Exp c) -> (Exp b -> Exp c) -> Exp (Either a b) -> Exp c
 - isLeft :: (Elt a, Elt b) => Exp (Either a b) -> Exp Bool
 - isRight :: (Elt a, Elt b) => Exp (Either a b) -> Exp Bool
 - fromLeft :: (Elt a, Elt b) => Exp (Either a b) -> Exp a
 - fromRight :: (Elt a, Elt b) => Exp (Either a b) -> Exp b
 - lefts :: (Shape sh, Slice sh, Elt a, Elt b) => Acc (Array (sh :. Int) (Either a b)) -> Acc (Vector a, Array sh Int)
 - rights :: (Shape sh, Slice sh, Elt a, Elt b) => Acc (Array (sh :. Int) (Either a b)) -> Acc (Vector b, Array sh Int)
 
Documentation
The Either type represents values with two possibilities: a value of
type  is either Either a b or Left a.Right b
The Either type is sometimes used to represent a value which is
either correct or an error; by convention, the Left constructor is
used to hold an error value and the Right constructor is used to
hold a correct value (mnemonic: "right" also means "correct").
Examples
The type  is the type of values which can be either
a Either String IntString or an Int. The Left constructor can be used only on
Strings, and the Right constructor can be used only on Ints:
>>>let s = Left "foo" :: Either String Int>>>sLeft "foo">>>let n = Right 3 :: Either String Int>>>nRight 3>>>:type ss :: Either String Int>>>:type nn :: Either String Int
The fmap from our Functor instance will ignore Left values, but
will apply the supplied function to values contained in a Right:
>>>let s = Left "foo" :: Either String Int>>>let n = Right 3 :: Either String Int>>>fmap (*2) sLeft "foo">>>fmap (*2) nRight 6
The Monad instance for Either allows us to chain together multiple
actions which may fail, and fail overall if any of the individual
steps failed. First we'll write a function that can either parse an
Int from a Char, or fail.
>>>import Data.Char ( digitToInt, isDigit )>>>:{let parseEither :: Char -> Either String Int parseEither c | isDigit c = Right (digitToInt c) | otherwise = Left "parse error">>>:}
The following should work, since both '1' and '2' can be
parsed as Ints.
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither '1' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleRight 3
But the following should fail overall, since the first operation where
we attempt to parse 'm' as an Int will fail:
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither 'm' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleLeft "parse error"
Instances
| Bifunctor Either | Since: 4.8.0.0  | 
| Eq2 Either | Since: 4.9.0.0  | 
| Ord2 Either | Since: 4.9.0.0  | 
| Read2 Either | Since: 4.9.0.0  | 
Methods liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Either a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Either a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Either a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Either a b] #  | |
| Show2 Either | Since: 4.9.0.0  | 
| NFData2 Either | Since: 1.4.3.0  | 
| Hashable2 Either | |
| Bitraversable1 Either | |
Methods bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> Either a c -> f (Either b d) # bisequence1 :: Apply f => Either (f a) (f b) -> f (Either a b) #  | |
| Swapped Either | |
| () :=> (Monad (Either a)) | |
| () :=> (Functor (Either a)) | |
| () :=> (Applicative (Either a)) | |
Methods ins :: () :- Applicative (Either a) #  | |
| (Lift Exp a, Lift Exp b, Elt (Plain a), Elt (Plain b)) => Lift Exp (Either a b) Source # | |
| Monad (Either e) | Since: 4.4.0.0  | 
| Functor (Either a) | Since: 3.0  | 
| MonadFix (Either e) | Since: 4.3.0.0  | 
| Applicative (Either e) | Since: 3.0  | 
| Foldable (Either a) | Since: 4.7.0.0  | 
Methods fold :: Monoid m => Either a m -> m # foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # toList :: Either a a0 -> [a0] # length :: Either a a0 -> Int # elem :: Eq a0 => a0 -> Either a a0 -> Bool # maximum :: Ord a0 => Either a a0 -> a0 # minimum :: Ord a0 => Either a a0 -> a0 #  | |
| Traversable (Either a) | Since: 4.7.0.0  | 
| (Elt a, Elt b) => Semigroup (Exp (Either a b)) # | |
| Eq a => Eq1 (Either a) | Since: 4.9.0.0  | 
| Ord a => Ord1 (Either a) | Since: 4.9.0.0  | 
| Read a => Read1 (Either a) | Since: 4.9.0.0  | 
Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Either a a0) # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Either a a0] # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Either a a0) # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Either a a0] #  | |
| Show a => Show1 (Either a) | Since: 4.9.0.0  | 
| MonadFailure (Either a) | |
| e ~ SomeException => MonadMask (Either e) | Since: 0.8.3  | 
| e ~ SomeException => MonadCatch (Either e) | Since: 0.8.3  | 
| e ~ SomeException => MonadThrow (Either e) | |
| NFData a => NFData1 (Either a) | Since: 1.4.3.0  | 
| Hashable a => Hashable1 (Either a) | |
| Elt a => Functor (Either a) Source # | |
| Generic1 (Either a :: * -> *) | |
| MonadBaseControl (Either e) (Either e) | |
| (Eq a, Eq b) => Eq (Either a b) | |
| (Ord a, Ord b) => Ord (Either a b) | |
| (Read a, Read b) => Read (Either a b) | |
| (Show a, Show b) => Show (Either a b) | |
| Generic (Either a b) | |
| Semigroup (Either a b) | Since: 4.9.0.0  | 
| (Lift a, Lift b) => Lift (Either a b) | |
| (NFData a, NFData b) => NFData (Either a b) | |
| (Hashable a, Hashable b) => Hashable (Either a b) | |
| (Elt a, Elt b) => Elt (Either a b) Source # | |
| (Eq a, Eq b) => Eq (Either a b) Source # | |
| (Ord a, Ord b) => Ord (Either a b) Source # | |
Methods (<) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # (>) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # (<=) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # (>=) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # min :: Exp (Either a b) -> Exp (Either a b) -> Exp (Either a b) Source # max :: Exp (Either a b) -> Exp (Either a b) -> Exp (Either a b) Source # compare :: Exp (Either a b) -> Exp (Either a b) -> Exp Ordering Source #  | |
| (Eq a, Eq b) :=> (Eq (Either a b)) | |
| (Ord a, Ord b) :=> (Ord (Either a b)) | |
| (Read a, Read b) :=> (Read (Either a b)) | |
| (Show a, Show b) :=> (Show (Either a b)) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Sum f g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Product f g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (f :+: g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (f :*: g) | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Sum f g) | |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Sum f g a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f0, Applicative f0) => p a (f0 a) -> Sum f g a -> f0 (Sum f g a) # ifoldr :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b #  | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Product f g) | |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Product f g a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f0, Applicative f0) => p a (f0 a) -> Product f g a -> f0 (Product f g a) # ifoldr :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b #  | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :+: g) | |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f0, Applicative f0) => p a (f0 a) -> (f :+: g) a -> f0 ((f :+: g) a) # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b #  | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :*: g) | |
Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifolded :: (Indexable (Either i j) p, Contravariant f0, Applicative f0) => p a (f0 a) -> (f :*: g) a -> f0 ((f :*: g) a) # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b #  | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Sum f g) | |
Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> Sum f g a -> f0 (Sum f g b) # itraversed :: (Indexable (Either i j) p, Applicative f0) => p a (f0 b) -> Sum f g a -> f0 (Sum f g b) #  | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Product f g) | |
Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> Product f g a -> f0 (Product f g b) # itraversed :: (Indexable (Either i j) p, Applicative f0) => p a (f0 b) -> Product f g a -> f0 (Product f g b) #  | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :+: g) | |
Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> (f :+: g) a -> f0 ((f :+: g) b) # itraversed :: (Indexable (Either i j) p, Applicative f0) => p a (f0 b) -> (f :+: g) a -> f0 ((f :+: g) b) #  | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :*: g) | |
Methods itraverse :: Applicative f0 => (Either i j -> a -> f0 b) -> (f :*: g) a -> f0 ((f :*: g) b) # itraversed :: (Indexable (Either i j) p, Applicative f0) => p a (f0 b) -> (f :*: g) a -> f0 ((f :*: g) b) #  | |
| type Failure (Either a) | |
| type StM (Either e) a | |
| type Rep1 (Either a :: * -> *) | |
type Rep1 (Either a :: * -> *) = D1 (MetaData "Either" "Data.Either" "base" False) (C1 (MetaCons "Left" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "Right" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1))  | |
| type Rep (Either a b) | |
type Rep (Either a b) = D1 (MetaData "Either" "Data.Either" "base" False) (C1 (MetaCons "Left" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "Right" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 b)))  | |
| type Plain (Either a b) Source # | |
left :: forall a b. (Elt a, Elt b) => Exp a -> Exp (Either a b) Source #
Lift a value into the Left constructor
right :: forall a b. (Elt a, Elt b) => Exp b -> Exp (Either a b) Source #
Lift a value into the Right constructor
either :: (Elt a, Elt b, Elt c) => (Exp a -> Exp c) -> (Exp b -> Exp c) -> Exp (Either a b) -> Exp c Source #
lefts :: (Shape sh, Slice sh, Elt a, Elt b) => Acc (Array (sh :. Int) (Either a b)) -> Acc (Vector a, Array sh Int) Source #
rights :: (Shape sh, Slice sh, Elt a, Elt b) => Acc (Array (sh :. Int) (Either a b)) -> Acc (Vector b, Array sh Int) Source #
Orphan instances
| (Lift Exp a, Lift Exp b, Elt (Plain a), Elt (Plain b)) => Lift Exp (Either a b) Source # | |
| (Elt a, Elt b) => Semigroup (Exp (Either a b)) Source # | |
| Elt a => Functor (Either a) Source # | |
| (Elt a, Elt b) => Elt (Either a b) Source # | |
| (Eq a, Eq b) => Eq (Either a b) Source # | |
| (Ord a, Ord b) => Ord (Either a b) Source # | |
Methods (<) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # (>) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # (<=) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # (>=) :: Exp (Either a b) -> Exp (Either a b) -> Exp Bool Source # min :: Exp (Either a b) -> Exp (Either a b) -> Exp (Either a b) Source # max :: Exp (Either a b) -> Exp (Either a b) -> Exp (Either a b) Source # compare :: Exp (Either a b) -> Exp (Either a b) -> Exp Ordering Source #  | |