Perl 6 Perl 6 today #67

Type-based dispatch

Rock-paper-scissors:

class Paper   { }
class Scissor { }
class Rock    { }

multi win(Paper $a,   Rock $b)    { 1 }
multi win(Scissor $a, Paper $b)   { 1 }
multi win(Rock $a,    Scissor $b) { 1 }
multi win(Any $a,     Any $b)     { 0 }

say win(Paper.new, Scissor.new);  # 0 
say win(Stone.new, Stone.new);    # 0
say win(Paper.new, Stone.new);    # 1
Copyright © 2009
http://www.pmichaud.com/2009/pres/