[Haskell-cafe] Applicative functors with branch/choice ?

Dominique Devriese dominique.devriese at cs.kuleuven.be
Thu Jul 26 07:28:35 CEST 2012


Евгений,

> The possible extension may look somehow like this:
>
> class Applicative a => Branching a where
>  branch :: a (Either b c) -> (a b -> a d) -> (a c -> a d) -> a d

What about the following alternative that does not require an extension?

  import Control.Applicative

  eitherA :: Applicative f => f (a -> c) -> f (b -> c) -> f (Either a b) -> f c
  eitherA = liftA3 either

Note by the way that the result of this function will execute the
effects of all of its arguments (as you would expect for an
Applicative functor).

Dominique



More information about the Haskell-Cafe mailing list