Em Sáb, 2009-03-28 às 13:36 +0300, Richard Hainsworth escreveu:
> Daniel Ruoso wrote:
> > The thing is that junctions are so cool that people like to use it for
> > more things than it's really usefull (overseeing that junctions are too
> > much powerfull for that uses, meaning it will lead to unexpected
> > behaviors at some point).   
> What are the general boundaries for junctions?

Junctions are superposition of values with a given collapsing type.

The most important aspect of junctions is that they are a singular
value, which means that they are transparent to the code using it. You
always use it as a singular value, and that's what keep its semantics
sane.

The boundary is where you try to use a junction as a plural value, and
that's where the semantics get weird...

> Perhaps, it might help to see some more examples of how junctions should 
> be used?

They should be used as a singular value... which means that the
blackjack example is only a good example for junctions, as far as to
know if the user has busted.

my @hand = 1|11, 9, 1|11;
my $sum = [+] @hand;
if ($sum <= 21) {
   # valid game
} else {
   # busted!
}

The semantic is sane that way because it doesn't make a difference if
there is a junction or not...

my @hand = 6, 9, 6;
my $sum = [+] @hand;
if ($sum <= 21) {
   # valid game
} else {
   # busted!
}

But even to compare two hands it gets weird...

my @a = 1|11, 9, 1|11;
my @b = 6,9,6;
my $pa = [+] @a;
my $pb = [+] @b;
if ($pa <= 21 && $pb <= 21) {
   if ($pa > $pb) {
        # B0RK3D
   }
}

That happens because $pa and $pb are a singular value, and that's how
junctions work... The blackjack program is an example for sets, not
junctions.

Now, what are junctions good for? They're good for situation where it's
collapsed nearby, which means, it is used in boolean context soon
enough. Or where you know it's not going to cause the confusion as in
the above code snippet.

Sets can provide the cool DWIMmery junction provides for the blackjack
case and still provide sane semantics for you to get its compound
values.

daniel

Reply via email to