🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
roguerakudev are there any plans to make arrays whose elements are all known to be of a given type compatible with typed array parameters? 02:19
e.g. sub foo(Int @ints) { ... } currently doesn't accept [1, 2, 3] as an argument 02:20
because [1, 2, 3] is technically untyped 02:21
[Coke] I haven't heard of it - I imagine it would be potentially costly.
roguerakudev I kinda get why it is the way it is, but it's rather annoying when you want to ensure things are of a certain type but don't want to impose an undue burden on callers
so you end up doing something like @param where @param.all ~~ Type or similar, and it feels a bit dirty 02:22
[Coke] sub foo(Int @ints) { dd @ints}; foo(Array[Int].new(1,2,3)) 02:23
evalable6 Array[Int].new(1, 2, 3)
evalable6_ Array[Int].new(1, 2, 3)
[Coke] can I recommend a multi with a strict type, and one with the manual type check? 02:24
roguerakudev yeah, Array[Foo].new(...) just seems needlessly verbose when it's clear that all elements are of type Foo (even at compile time)
Coke - in the end I will probably just remove the constraint and trust the caller 02:25
I like the idea that the programmer can start prototyping without type constraints and then add them as the design cements, but right now this behavior discourages me from adding in typing in many cases 02:27
ugexe the pattern i ended up following was using a separate assignment altogether, i.e. `my Candidate @results = @candidates; return @results;` 02:28
either way, it is a bit unfortunate it requires copying 02:30
roguerakudev more generally, parameterized types don't currently DWIM imo, but there's probably some edge case that prevents Foo[Bar] from being a subtype of Foo[Baz] in every case even if Bar is a subtype of Baz
maybe in an ideal world we'd have some way to mark such edge cases while the default is that Foo[Bar] ~~ Foo[Baz] (e.g. Array[SomeType] ~~ Array[Any]) 02:32
or maybe the default is the other way, and things like Array are marked as having that property, whatever that property would be called 02:33
oh wait, that already is the case 02:38
[1, 2] isn't even Array[Any], it's just Array - but somehow I expect the absence of that type parameter to make it default to Any, so maybe that's the crux of the issue 02:39
bah, I'm on too little sleep for all this reasoning 02:41
for reference, Positional's type defaults to Mu, but Any vs. Mu doesn't really matter in this context github.com/rakudo/rakudo/blob/881c...rakumod#L1 02:42
so maybe it's sufficient for list/array/hash literals to take on the most specific common type of the elements as their associated role/class's type parameter? 02:44
if [1, 2] were always Array[Int], that shouldn't (?) break anything given that Positional[Int] is compatible with Positional[Mu] 02:45
Xliff m: say 1, 1, 2, 3...*+* 04:33
camelia (1 1)
Xliff Why isn't that sequence evaluating?
m: say 1, 1, 2, 3..*+*
camelia 112WhateverCode.new
nahita3882 > If the endpoint is not , it's smartmatched against each generated element and the sequence is terminated when the smartmatch succeeded. in your case the endpoint is a WhateverCode with arity 2, so it takes the first 2 elements of the sequence which are 1 and 1, subjects it to ` + *` which gives 1 + 1 = 2, which is truthful so the sequence is terminated and yields 1, 1 09:39
did you mean 1, 1, * + * ... *?
(your second message was evaluating to a List with 4 elements: 1, 1, 2 and a WhateverCode with the body 3 .. * + *, i.e., a Range maker from 2 arguments) 09:41
dr.shuppet Oh so that's what it says, I didn't see the italics and didn't realize there are *s in there 17:05
m: say (1, 1, 2, 3, * + * ... *)[0..10] 17:07
evalable6 (1 1 2 3 5 8 13 21 34 55 89)
Raku eval (1 1 2 3 5 8 13 21 34 55 89)
Geth docker: m-dango++ created pull request #65:
Bump to 2024.04
17:33