[Haskell-cafe] Applicative functors with branch/choice ?
permeakra at gmail.com
Wed Jul 25 22:22:23 CEST 2012
Let assume, that some computation takes argument and produces value
Either a b. This computation may be represented in for different forms
computePure :: a -> Either b c
computeMonad :: a -> m (Either b c)
computeApplicative :: app a -> app (Either b c)
computeArrow :: arr a (Either b c)
And now, having result, we need to execute several actions, making a
choice, what actions to perform for Left and Right tags of Either. Pure
function and monads are easy, as there is way to pattern-match on value
and take actions depending on result. There is an extension to Arrow
class that do the job -- ArrowChoice. However, I cannot find any way to
make choice for Applicative. It seems that both Applicative and
Alternative are not suited for it.
So, it seems for me, that Applicative API should be extended with
typeclass for making choice what actions to execute depending on result
of some test (pattern matching). Is there any reasonable definition of
such typeclass or clear explanation, why such typeclass is unneeded?
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
More information about the Haskell-Cafe