Alternative. , , Alternative Semigroup, - , : Maybe String:
λ > Just "a" <> Just "b"
Just "ab"
λ > Just "a" <> Nothing
Just "a"
λ > Nothing <> Just "b"
Just "b"
λ > Nothing <> Nothing
Nothing
λ > Just "a" <|> Just "b"
Just "a"
λ > Just "a" <|> Nothing
Just "a"
λ > Nothing <|> Just "b"
Just "b"
λ > Nothing <|> Nothing
Nothing
, , -, Just "a" Just "b". , Semigroup, Alternative.
Alternative Either. , Alternative:
λ > :i Alternative
class Applicative f => Alternative (f :: * -> *) where
empty :: f a
(<|>) :: f a -> f a -> f a
some :: f a -> f [a]
many :: f a -> f [a]
{-# MINIMAL empty, (<|>) #-}
, empty; (<|>). , - - .
, Either e a? Alternative, , f Applicative. , Either Applicative, Either e. , Either (a Either e a). , Either e e, . , e Alternative, Alternative Either e, ( - : (Alternative e, Applicative (f e)) => Alternative (f e)).
TL; DR: , , f Either , Alternative f :: * -> *, Either Either :: * -> * -> *
, Maybe Alternative, Maybe : * -> * (Nothing), empty. Alternative .
ghci :k:
λ > :k Maybe
Maybe :: * -> *
λ > :k Either
Either :: * -> * -> *