04:46 kurahaupo joined 06:48 kurahaupo left 07:28 lizmat joined 07:53 kurahaupo joined, dakkar joined 08:12 lizmat left 10:44 kurahaupo left
disbot <demanddystopia> late response but I believe Type signatures with @ and % just in general mean "Positional/Associatice that is marked as containing only the declared Type" and nothing else 10:52
<demanddystopia> guess to really get a variable with % sigial that has to be a Hash inside the signature one would need to use where ? 10:53
10:56 kurahaupo joined
disbot <demanddystopia> ok at least think something like sub abc(%h where * ~~ Hash) {; sub abc(%h where *.^name eq 'Hash') {;} sub abc(%h where {.^name eq Hash.^name}) {;} seem to work, accepts stuff created as my %hash = … but rejects my %bh is BagHash = … 11:14
<demanddystopia> scratch that, it's as simple as sub abc(%h where Hash) {;}, forgot you can just do that 11:19
13:18 camelia left, camelia joined 13:27 kurahaupo left 13:45 leifgunnar left, kjp left, cpli left, disbot left 13:50 lizmat joined 13:51 leifgunnar joined, kjp joined, cpli joined, disbot joined 13:52 disbot left, disbot3 joined 13:53 disbot3 is now known as disbot 14:05 lizmat left
ab5tract Associative is parametric with two usable options. Associative[Value,Key = Str]. Key is second because it is less likely to changed as Str is usually good enough 14:40
sorry, that's Hash[Value, Key = Str]. 14:44
m: my %h is Hash[Str, Int]; %h<ok> = 42; %h{42} = "ok" 14:45
camelia Type check failed in binding to parameter 'key'; expected Int but got Str ("ok")
in block <unit> at <tmp> line 1
ab5tract So it's essentially 3 details (at least)
1. use of a % container requires use of `is` have the regular type declaration semantics (ie what usually goes between "my" and "$h" but fails between "my" and "%h") 14:47
2. Key comes after Value when declaring the type 14:48
3. I forget the third one (a real C.R.A.F.T. moment -- cuz I can't remember a fricking thing) 14:49
Ah, right!
3. Containers that contain a specific type structure do *not* automatically fit into a container that is declared as fitting that type structure -- the types have to match 14:50
m: my %h is Hash[Str, Int] = %( 44 => "nok" ) 14:51
camelia Type check failed in binding to parameter 'key'; expected Int but got Str ("44")
in block <unit> at <tmp> line 1
ab5tract m: my %h is Hash[Str, Int] = :{ 42 => "nok" } # object hash does work 14:52
camelia ( no output )
ab5tract This is certainly a source of some confusion and I recall there being significant discussion around in some years ago 14:54
m: my Int @a; my @b = [1,2,3]; dd @a = @b 14:55
camelia Int = Array[Int].new(1, 2, 3)
ab5tract that works fine but...
m: my Int @a; my @b = [1,2,3]; dd @a := @b
camelia Type check failed in binding; expected Positional[Int] but got Array ([1, 2, 3]). You have to pass an
explicitly typed array, not one that just might happen to contain
elements of the correct type.
in block <unit> at <tmp> line 1
ab5tract thowe: I hope the above clears up a bit of the confusion. Please feel free to ping me for further clarification 14:56
16:30 dakkar left 20:21 lizmat joined 22:04 lizmat left 23:12 kurahaupo joined