Does Perl6 support dependent types?

后端 未结 2 1164
南旧
南旧 2021-02-13 13:22

I was recently looking at the wikipedia page for dependent types, and I was wondering; does Perl 6 actually introduce dependent types? I can\'t seem to find a reliable source cl

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-13 14:03

    Against Ven, in the comments following the Perl 6 answer to the SO question "Is there a language with constrainable types?", wrote "perl6 doesn't have dependant types" and later wrote "dependent type, probably not, ... well, if we get decidable wheres..." in an exchange on #perl6. (Larry Wall's response was "what's a few halting problems among friends". Btw, by far the best way to get an authoritative answer on all things Perl 6 is to ask TimToady via #perl6.)

    For The summary for the 'dependent-type' SO tag is "Dependent types are types that depend on values." Perl 6 supports types that depend on values, so there's that.

    For The edit summary for the change by Awwaiid that added Perl 6 to Wikipedia's page on Dependent Types says "Perl 6 ... has undecidable dependent types".

    The Wikipedia page starts with:

    a dependent type is a type whose definition depends on a value. A "pair of integers" is a type. A "pair of integers where the second is greater than the first" is a dependent type because of the dependence on the value.

    Here's one way to create a type along those lines in Perl 6:

    subset LessMorePair of Pair where { $_.key < $_.value }
    subset MoreLessPair of Pair where { $_.key > $_.value }
    
    multi sub foo (        Pair) { "  P" }
    multi sub foo (LessMorePair) { "LMP" }
    multi sub foo (MoreLessPair) { "MLP" }
    
    for 1 => 1, 1 => 2, 2 => 1 { say foo $_ }
    
    #   P
    # LMP
    # MLP
    

    Does this mean the Perl 6 subset feature generates dependent types? Perhaps this is what Awwaiid is thinking of.

提交回复
热议问题