|
00:24
frost joined
00:58
frost left
04:58
frost joined
05:49
frost left
13:05
A26F64 joined
17:16
A26F64 left
|
|||
| leobm | can i simulate something like typeclasses in raku? | 17:33 | |
| So the type should have a role (e.g. Countable) and then | |||
| use a very specific implementation for it based on this role and the type | |||
| ``` | |||
| role Countable is export { | |||
| proto sub count(--> Int) is pure {*} | |||
| } | |||
| my $s = "dsad" but Countable; | |||
| say $s.count(); ## should call an implementation for Str | |||
| my @a = <a b c> but Countable; | |||
| say @a.count() ## should call an implementation for Array; | |||
| ``` | |||
| lizmat | m: role Foo { method bar { ... } }; class Baz does Foo { } | 17:34 | |
| camelia | ===SORRY!=== Error while compiling <tmp> Method 'bar' must be implemented by Baz because it is required by roles: Foo. at <tmp>:1 |
||
| leobm | maybe something similar to implicit-conversions in scala? But with raku roles.... | 17:35 | |
| I came across this question because I was looking at the following module: modules.raku.org/dist/Colorizable:...le.rakumod | 17:39 | ||
| But there is the implementation in the role itself (for Str) | |||
| But what if I want to make e.g. another type Colorizable? | |||
| i have seen that i can give parameters to the role itself. | 17:40 | ||
| e.g. | |||
| ``` | |||
| role Countable[::T] is export { | |||
| proto sub count(--> Int) is pure {*} | |||
| } | |||
| ``` | |||
| Can I do something with this? | |||
| lizmat | the ::T is a very specific one | 17:41 | |
| it's more general | |||
| m: role max-value[$max = Inf] { ... } | |||
| camelia | ( no output ) | ||
| lizmat | so you can have default values for the parameters you''re passing | 17:42 | |
| the ::T case is really if you want to specify types to which you want to constrain variables later | |||
|
20:11
MasterDuke joined
|
|||