4 ms·
Avoid a Common Software Bug by Using Perl 6
- raiph 12y agoA comment on Ovid's blog post says: > Perl 6 does some compile time type checking but it only works in some very simple cases. I was thinking that all P6 code had static types that were checked at compile-time and some code, not much, also had dynamic types that were checked at run-time. In the form of a question/answer series, here's how I thought things worked: > When are types checked? Static types are checked at compile-time. > What's a "static type"? Class types like Any, Int, Str, and users' classes. Additionally, static subsets. > What's a "static subset"? Subsets are the subsets introduced by Ovid in the OP. A static subset is one that the compiler has decided to reduce to and treat as a finite set. The compiler may treat Wday in the following code as a static subset and thus a static type: my enum Day <Su M Tu W Th F Sa>; subset Wday of Day where M .. F; Currently Rakudo does not treat any subsets as static types. > So what are dynamic types? Subsets that aren't (treated as) static are (treated as) dynamic subsets and are thus treated as dynamic types. These are the only dynamic types. > Which code avoids dynamic types and hence is fully type-checked at compile time? All "untyped" code. Scalar containers ($foo, @bar[1], @bar[2] etc.) and values are assigned the static type Any. Of course this is pretty trivial but it is type checking and it does happen at compile-time. :) Most if not all the code in the core libraries. Most of the code in the ecosystem. ---- I'd appreciate correction or wholesale destruction of any wrong ideas in the above. I'm particularly suspicious about methods. :)