Question regarding arrows...

Ross Paterson ross@soi.city.ac.uk
Mon, 7 Jul 2003 10:22:31 +0100


On Sun, Jul 06, 2003 at 05:31:59PM +0100, MR K P SCHUPKE wrote:
> I am trying to define the left operator for a CPS arrow of type:
> 
> newtype CPSFunctor ans a b c = CPS ((a c ans) -> (a b ans))
> 
> [...]
> So I try and apply this to left and get:
> 
> left (CPS f) = CPS $ \k -> arr (\z -> case z of
> 	Left x -> (f (arr Left >>> k),x)
> 	Right x -> (arr Right >>> k,x)) >>> app

The error message is confusing, but the underlying problem isn't
GHC-specific: the case forces the two x's (representing alternatives in
the incoming Either) to have the same type, which isn't what is required
for left.  Here's an alternative (an instance of the general definition
of left for ArrowApply given by Hughes):

        left (CPS f) = CPS $ \k -> arr (\z -> case z of
                Left b -> (arr (\() -> b) >>> f (arr Left >>> k), ())
                Right d -> (arr (\() -> Right d) >>> k, ())) >>> app