Perl 6 Cool Perl 6 #90

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 © 2010
http://www.pmichaud.com/2010/pres/