Re: A newbie question about Arrows.

2003-01-09 Thread Shawn P. Garbett
On Monday 06 January 2003 04:02 am, Nicolas Oury wrote:
 I think for example to event-driven arrows : we could make a pair of
 inputs without mixing the event happened information.

Here's one that's been baffling me: What about the case where you have two 
arrows you want to combine. Suppose that each of these arrows are a stream 
processor, which process the type Either.

SP (Either a b) (Either a b)

Now combing these with the sequencing operator is straightforward. The output 
of the first SP becomes the input of the second.

() :: SP i o - SP i o - SP i o

Or in a routing diagram

In - SP1 -- SP2 -- Out

But what if you wanted to mix up the routing of Left and Right from the Either 
above?

In(Left) - SP1(Left)
In(Right) - SP2(Right)
SP1(Right) - SP2(Left)
SP2(Left) - SP1(Right)
SP1(Left) - Out(Left)
SP2(Right) - Out(Right)

One could easily define an operator to do this, but then what if one wanted to 
combine three arrows with arbitrary routing of the signal? The problem 
becomes combinatorial quickly. Yet this is exactly what happens in circuit 
design and signal routing, or complex object oriented code. I imagine this 
like a multi-layer circuit board, each SP maintains it's own state and 
operates on multiple streams. The routing of these streams is arbitrary and 
complex.

Maybe I'm just missing something trival and there's a simple way to do this 
already with arrows.

Shawn
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: A newbie question about Arrows.

2003-01-08 Thread Ashley Yakeley
In article [EMAIL PROTECTED],
 Ross Paterson [EMAIL PROTECTED] wrote:

 The arrow notation is closely tied to products.

Perhaps, but it doesn't have to be part of the class. I prefer this, for 
aesthetic reasons:

  class Arrow a where
 arr :: (b - c) - a b c
 () :: a b c - a c d - a b d
 arrApply :: a b (c - d) - a b c - a b d

From this one can derive:

  proj1 (b,d) = b
  proj2 (b,d) = d
  product c d = (c,d)

  arrProduct :: (Arrow a) = a b c - a b d - a b (c,d)
  arrProduct abc abd = arrApply (abc  (arr product)) abd

  -- Hughes' 'first'
  arrFirst :: (Arrow a) = a b c - a (b,d) (c,d)
  arrFirst abc = arrProduct ((arr proj1)  abc) (arr proj2)

There only needs to be one class, and you can use whatever product you 
like by using the appropriate functions for 'proj1', 'proj2' and 
'product'.

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/hbase/Source/H
Base/Category/Arrow.hs?rev=HEADcontent-type=text/plain

-- 
Ashley Yakeley, Seattle WA

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: A newbie question about Arrows.

2003-01-07 Thread Nicolas.Oury
I may be totally wrong, but I read in Hughes paper than in Stream
Processors, Either is more a product than (,) . It could be interesting
to parameter the arrow by product, in order than the multiplexing is done
using this product when using the new notation for arrow.


Best regards,
Nicolas Oury

On Mon, 6 Jan 2003, Ashley Yakeley wrote:

 At 2003-01-06 03:14, Ross Paterson wrote:

 class PreArrow ar where
  arr :: (a - b) - ar a b
  () :: ar a b - ar b c - ar a c
 ...
  class (PreArrow ar, Monoidal p u) = GenArrow ar p u where
  first :: ar a b - ar (p a c) (p b c)

 My own preference is something like this:

   class (PreArrow ar) = GenArrow' ar where
   arrApply :: ar p (q - r) - ar p q - ar p r

 My GenArrow' is actually equivalent to Hughes' Arrow and I assume your
 GenArrow.

 In an ideal world, I could leverage my FunctorApply class to have
 something like this:

   class (Functor f) = FunctorApply f where
   -- first arg (fab) executed first
   fApply :: f (a - b) - (f a - f b)

 -- first arg (fa) executed first
 fPassTo :: f a - f (a - b) - f b
 fPassTo fa fab = fApply (fmap (\a ab - ab a) fa) fab

   class (PreArrow ar,forall p. FunctorApply (ar p)) = GenArrow'' ar

 Unfortunately, GHC does not yet allow this kind of superclassing.

 http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/hbase/Source/HBa
 se/Category/Functor.hs?rev=HEADcontent-type=text/plain
 http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/hbase/Source/HBa
 se/Category/Arrow.hs?rev=HEADcontent-type=text/plain

 --
 Ashley Yakeley, Seattle WA



___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: A newbie question about Arrows.

2003-01-07 Thread Ross Paterson
On Tue, Jan 07, 2003 at 06:22:53PM +0100, Nicolas.Oury wrote:
 I may be totally wrong, but I read in Hughes paper than in Stream
 Processors, Either is more a product than (,) . It could be interesting
 to parameter the arrow by product, in order than the multiplexing is done
 using this product when using the new notation for arrow.

The arrow notation is closely tied to products.  If you want to write
an expression containing several variables, you need a tuple containing
values for those variables (an environment).  An asynchronous stream
processor gives you a value for only one channel at a time.  Bridging
this gap won't be easy, but it's what Magnus is attempting in the work
I referenced.  Essentially he builds a tuple containing the last value
received on each channel, waiting until all channels have produced.
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: A newbie question about Arrows.

2003-01-06 Thread Ross Paterson
On Mon, Jan 06, 2003 at 11:02:32AM +0100, Nicolas Oury wrote:
 * Why is made the choice to use (,) as Cartesian in first?

It's certainly possible to define a more general interface, and the
theoretical work does.  However the arrow interface is already very
general, and the question is whether any programs can be written to
the more general interface.  Magnus Carlsson has some ideas along
these lines (see http://www.cse.ogi.edu/~magnus/ProdArrows/).

I will quibble with some of the details, though:

 Can't we write something like :
 
 class Cartesian p where
 pair :: a - b - (p a b)
 projLeft :: (p a b) - a
 projRight :: (p a b) - b
 
 class Cartesian pair = Arrow ar where
   arr ::( ar pair a b) - (ar pair a b)
   () :: (ar pair a b) - (ar pair b c) - (ar pair a c)
   first :: (ar pair a b) - (ar (pair a d) (pair b d))

First, you don't need pair for the first two, so one might define

class PreArrow ar where
arr :: (a - b) - ar a b
() :: ar a b - ar b c - ar a c

Second, we don't really need pair to be quite as product-like.  What we
really want is for it to be monoidal, i.e. a binary functor with a
unit type u and isomorphisms

type Iso a b = (a - b, b - a)

class Monoidal pair u | pair - u where
unitl :: Iso (pair u a) a
unitr :: Iso (pair a u) a
assoc :: Iso (pair a (pair b c)) (pair (pair a b) c)

satisfying a few axioms.  For products (pretending that Haskell has
products), we use pair = (,), u = (), unitl = fst and unitr = snd.
For sums (useful for asynchronous event streams), pair = Either and
u = an empty type.

Then one could define

class (PreArrow ar, Monoidal p u) = GenArrow ar p u where
first :: ar a b - ar (p a c) (p b c)

which would subsume Arrow and ArrowChoice.  Some of the Theoretical
Asides in the Arrow Notation paper discuss this possibility.

 * Why is made the choice of first as being a base function?
 
 We have
 
 first f = f *** (arr id)
 
 second f = (arr id) *** f
 
 So they could be define from (***).
 
 Moreover,  the definition of f *** with first and second creates an 
 order in the use of the f and g (first f  second g) whereas it seems 
 that (***) is a parallel  operator.

This is discussed in John Hughes's paper (end of 4.1).  The essential
point is that the appearance of symmetry is illusory.  For many arrows,
including Kleisli arrows of common monads, the ordering is there, even
though the notation *** hides it.
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe