Custom Search
|
Re: Arrows in Scala
Date: December 28, 2006
In-reply-to:
<8081081.post@xxxxxxxxxxxxxxx> On 12/28/06, steve.bendiola <steve.bendiola@xxxxxxxxx> wrote:
I guess by Either type, it is meant something like (maybe we should add this one to the library) case class Left[A,B](x:A) extends Either[A,B] case class Right[A,B](x:B) extends Either[A,B] This is a generic way to encode a type theoretic sum (coproduct). Left and Right are called "injections", they turn a value x of type S into a value of type Either[S,T] (or Either[T,S], resp). One can then later recover what the result was by matching def distinguish(e:Either[S,T]) = e match { case Left(x) => // was left, x has type S case Right(y) => // was right, y has type T } It is called a *co*product, because consider that Tuple2[A,B] is a product, you need both components to construct it and once you have a product there are two projections functions, namely _1 and _2. You can draw all these in nice diagrams where a product is a coproduct with all arrows reversed. It seems like an interesting exercise to model products and sums with Arrows (capital A). hope this helps, Burak -- Burak Emir Research Assistant / PhD Candidate Programming Methods Group EPFL, 1015 Lausanne, Switzerland http://lamp.epfl.ch/~emir |