标签:mono imp type cte mfp int wrap acm hidden
There is more than one way to do it.
subset
关键字,它用于定义一个类型的子集subset Non-neg-int of Int where { $_ >= 0 }
# factorial as example
sub factorial(Non-neg-int $n) {
return 1 if $n == 0;
return $n * factorial $n-1;
}
> fact(1.5)
Type check failed in binding to parameter ‘$n‘; expected Int but got Rat (1.5)
in sub fact at <unknown file> line 1
in block <unit> at <unknown file> line 1
> fact(-1)
Constraint type check failed in binding to parameter ‘$n‘; expected Non-neg-int but got Int (-1)
in sub fact at <unknown file> line 1
in block <unit> at <unknown file> line 1
标签:mono imp type cte mfp int wrap acm hidden
原文地址:http://www.cnblogs.com/wander4096/p/7462470.html