Re: Functional-style pattern matching

2010-03-10 Thread Little Walker
 That's almost exactly the example from:

    http://perlcabal.org/syn/S06.html#Unpacking_tree_node_parameters

1. I feel incredibly embarrassed to have missed this
2. This is awesome!



Re: Functional-style pattern matching

2010-03-10 Thread Little Walker
 Which is pretty powerful, really.

Absolutely - I think you're referring to the 'type subset' stuff which
is great.

 This is where Perl 6 is not the same as functional
 languages, since it's got an imperative OO element as well.

True, there can be friction between the functional style and OO, but
look at how Scala manages it with case classes.  When you look at the
implementation, really it boils down to syntactic sugar but then so do
many of the cool new features in Perl 6!

I bring this up because when thinking of what will be possible with
lazy evaluation, junctions, named parameter shorthand, closures, etc.,
etc., somehow pattern matching screams out at me.  It can be concise,
expressive and unambiguous, and very complementary to Perl 6's
existing feature set.  I know a lot of work went into bringing
functional and OO together to make Scala happen, so certainly there
may be impracticalities in just 'adding pattern matching'.

Scala case classes: http://www.scala-lang.org/node/107 or
http://programming-scala.labs.oreilly.com/ch06.html#CaseClasses



Functional-style pattern matching

2010-03-09 Thread Little Walker
Hi there,

I've been looking around to see if there's been any discussion of
introducing functional programming-style pattern matching for method/
function dispatch.  Could someone point me to any such discussions?

I've seen that perl6 is taking on a lot of ideas from the functional
world (lazy evaluation for instance).  With multi-method dispatch on
the agenda pattern matching seems inevitable but I haven't been able
to find information about this or any related discussions.

This is a contrived example of what I'm referring to:

sub traverse([Leaf $a]) {
  # do something
}

sub traverse([Tree $left, Tree $right]) {
  traverse($left);
  traverse($right);
}

my $t = Tree(...);
traverse($t);

---

Many thanks!