Re:Perl 6 – Getting beyond static vs. dynamic [pdf]
by tel on Sunday February 22, 2015 @07:12PM
(#9091852)
The idea of trying to move subset types forward is interesting. Using an SMT solver [0] you can move quite a bit forward. Otherwise, generally, you're talking about associating a dictionary of pre- and post-conditions with a type (e.g., Weekday is a new nominal type isomorphic with Day, but it also has an associated dict containing checks that it's within Mon-Fri). Carrying that dict around has been well-solved by Haskell's typeclass compilation machinery and then it's just a matter of inserting the checks at the right times and not more often, I suppose.
Re:Perl 6 – Getting beyond static vs. dynamic [pdf]
by raiph on Sunday February 22, 2015 @07:41PM
(#9091945)
Perhaps you're aware that one of the biggest influences on P6 was Haskell and the 2005-2007 Audrey Tang / Pugs / lambdacamels era. Loads of crazy smart kids sharing wild thoughts with Larry, Damian etc. and writing the first P6 compiler in Haskell.
I've not actually checked the following code yet. I just wanted to post it now and will return to update after I've tested this stuff tonight, but here's what I'm currently thinking:
* The Any type is the default value type.
* Built-in literals are automatically converted in to more specific value types at the time they are encountered by the compiler:
* User defined literals and run-time string input are also supposed to be optionally automatically converted from an Any into a more specific type on assignment, but that's not yet implemented in the Rakudo P6 compiler.* Optional explicit types improve type-checking on assignment:
* Not yet implemented but due to land soon: * And for calls: * Optional explicit types enable multisub dispatch: * P6 allows users to introduce "subsets". Subsets combine a base type (always static/compile-time) with additional constraint logic. The additional constraint may force the subset to become partially dynamic rather than solely static.* Subsets can be applied in an assignment or signature:
* The additional constraint logic of a subset is a P6 "smart match" -- arbitrary code that accepts or rejects a specific value of the base type. In the Weekday subset above the constraint logic is `'Mon' .. 'Fri';`.* If code analysis can deduce a finite set from the combination of base type and the additional constraint logic, then a compiler may choose to make the whole subset static and check and resolve calls and constrained assignments at compile-time. Otherwise the static part of a subset is checked at compile-time, which may lead to a particular call being among the candidates for a final dispatch, and then there may be a final round of call resolution and checking at run-time.
* Assignments and function calls that don't involve dynamic subsets, or where the compiler can eliminate them from consideration at compile-time, are type checked and dispatch resolved at compile-time.
* Methods are always dispatch resolved at run-time.
[1] http://en.wikipedia.org/wiki/Nominal_type_system