develooper Front page | perl.perl6.users | Postings from February 2019

Typed Arrays and for-loops

Thread Next
From:
Mikkel
Date:
February 13, 2019 12:29
Subject:
Typed Arrays and for-loops
Message ID:
CANUJ3NpgHqHaL=jW1fVnPuNjimqXTcNo+4c1GEP=At-J4WBQNA@mail.gmail.com
Hello. (recurring noob-question here)

I seem always seem to get myself confused with Arrays/Typed Arrays. Can I
ask of you to explain why the 'for' loop does not work without .flat? It
seems so counter intuitive....

> my Array[Str] $files;
(Array[Str])

> $files.push("Test");
[Test]

> $files.push("Test 2");
[Test Test 2]

> for $files -> Str $f {.say}
Type check failed in binding to parameter '$f'; expected Str but got
Array[Str] (Array[Str].new("Test", "Test 2"))
  in block <unit> at <unknown file> line 1

Best regards
Mikkel Birkedam

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About