Sunday, February 25, 2007

Perl 6: Junctions?

The Perl people are either onto something really fascinating, or have just plain gone nuts.

My latest discovery in the alleged Perl 6 project -- alleged because there's only so long you can go without producing results -- is junctions, which are a datatype which can have any of several specified values.

No, really.

Update -- it turns out that the primary use case for this new language feature is something you already get for free in Ruby.

5 comments:

  1. Unless things have changed radically since I was writing the Perl 6 Summaries, Perl 6 has a splat operator too.

    Sure, junctions are used in the Perl 6 case statement, but that that's far from being their only possible use, they can also be used in non deterministic search type applications (the sort of thing that involves heavy continuation based lifting in Ruby).

    The idea itself flows from Damian Conway's Quantum::Superpositions module. Originally written in Perl 5, it proved to be a startlingly powerful way of thinking about some problems, but it can't really be fully implemented in Perl 5 because the runtime lacked a couple of things.

    Junctions need to be the language at a fairly fundamental language to make them properly useful in the cases where you need them, but those cases aren't particularly easy to explain. Their use in case statements where Ruby uses splat is a side effect, not a raison d'etre.

    ReplyDelete
  2. OK, well, anything that starts with quantum physics and ends with an unusual language feature is Giles bait on a par with Salma Hayek covered in lime-green jello, so I went hunting that sucker down. Didn't find it yet, but so far I found this:

    http://en.allexperts.com/e/p/pe/perl_6.htm

    According to which, it looks as if the Perl 6 answer to "Static typing or dynamic typing?" is going to be "Yes!"

    ReplyDelete
  3. Here's the module (not maintained by Damian any more): http://search.cpan.org/~lembark/Quantum-Superpositions-2.02/lib/Quantum/Superpositions.pm

    As for the type thing, they're following Common Lisp which has an optional typing system. Type annotations can be used by the compiler to generate more efficient code. I'm not usre it's going to be in the first cut of Perl 6, but there's plans in the wind for doing type inferencing a la Haskell.

    And, if it makes hard core "It must have static type declarations or it's not a *real* language" folks happy without getting in the way of folks like me who'd far rather stay purely dynamic, what's not to like?

    ReplyDelete
  4. BTW, Damian does way more impressive things with Quantum::Superpositions than are documented in the module. He gave a fabulous talk on 'Life, the Universe, and Everything' in which he ended up simulating a simple gas using a cellular automaton with a superposed set of rules.

    And, if obscure language features are your thang, you'd probably enjoy any of Damian's talks listed here: http://damian.conway.org/Seminars/

    ReplyDelete
  5. Like everything else in perl 6: you can already have it today.

    ReplyDelete

Note: Only a member of this blog may post a comment.