Question regarding arrows...

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)) This is the definition given by John Hughes for first: first (CPS f) = CPS $ \k -> arr (\(b,d) -> (f (arr (\c -> (c,d)) >>> k),b)) >>> app 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 But when I compile (with ghc-6.0) I get: Inferred type is less polymorphic than expected Quantified type variable `d' is unified with another quantified type variable `b' When trying to generalise the type inferred for `left' Signature type: forall ans a. (ArrowApply a, ArrowChoice a) => forall b1 c1 d1. CPSFunctor ans a b1 c1 -> CPSFunctor ans a (Either b1 d1) (Either c1 d1) Type to generalise: forall b1 c1 d1. CPSFunctor ans a b1 c1 -> CPSFunctor ans a (Either b1 d1) (Either c1 d1) In the instance declaration for `ArrowChoice (CPSFunctor ans a)' Hughes says in his paper that "CPS arrows ... can of course support dynamic choice" - so where am I going wrong with my definition? Any help greatly appreciated... Regards, Keean Schupke.

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
participants (2)
-
MR K P SCHUPKE
-
Ross Paterson