Some languages don't really care about types and allow to write something like (define (w x) (x x)) or even worse stuff.
Are there any statically-typed languages that allow to mock the mockingbird?
# The multi keyword is for overloading functions
multi func ($val) {
say "untyped '$val'"
};
multi func (Int $val) {
say "Integer $val"
};
func('a'); # Prints the message: untyped 'a'
func(1); # Prints the message: Integer 1
It can check other conditions also:
# %% is the 'divisible by' operator
sub func (Int $x where $x %% 2) {
say "even number"
};
func (2); # Prints the message even number
func (1); # Gives you an error
Name:
62013-03-05 15:41
I might have answered a different thing, OP: check this code too
my Int $num = 123;
my Str $name = "Baka-san";
my @array_of_shit = ($num, $name);
say @array_of_shit.perl;
say @array_of_shit[0].WHAT, @array_of_shit[1].WHAT;
This code will print
«Array.new(123, "Baka-san")
(Int)(Str)»