Typed Pairs

--000000000000305e970591cd8a48
Content-Type: text/plain; charset="UTF-8"

Hello

I am wondering whether it is possible to define a Pair with a key and a
value of a specific class.

Suppose I want an Array of Pairs with keys as Str and values as Array of
Str called "properties". And define it as a instance variable.Something of
the likes:

has Pair[Str, Array[Str]] @!properties;

Except this wont work.


Best regards
Mikkel

--000000000000305e970591cd8a48
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello</div><div><br></div><div>I am wondering whether=
 it is possible to define a Pair with a key and a value of a specific class=
..</div><div><br></div><div>Suppose I want an Array of Pairs with keys as St=
r and values as Array of Str called &quot;properties&quot;. And define it a=
s a instance variable.Something of the likes:<br></div><div><br></div><div>=
has Pair[Str, Array[Str]] @!properties;</div><div><br></div><div>Except thi=
s wont work.</div><div><br></div><div><br></div><div>Best regards</div><div=
>Mikkel<br></div></div>

--000000000000305e970591cd8a48--
0
mikkelsteen
9/5/2019 12:34:05 PM
perl.perl6.users 1217 articles. 0 followers. Follow

2 Replies
8 Views

Similar Articles

[PageSpeed] 55

--000000000000fa2d850591d01deb
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

this looks like two questions-

typing Array contents - see Typing
<https://docs.perl6.org/language/list#___top>
Syntax is "my @bucket of TypedThings;"

typing a Pair

> my Pair[Str, Array[Str]] $x;
=3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
An exception occurred while parameterizing Pair
at <unknown file>:1
Exception details:
  =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
  Pair cannot be parameterized
  ------> my Pair[Str, Array[Str]]=E2=8F=8F $x;

Yep doesn't work! Must be a way, I don't know it...

-y


On Thu, Sep 5, 2019 at 5:34 AM Mikkel <mikkelsteen@gmail.com> wrote:

> Hello
>
> I am wondering whether it is possible to define a Pair with a key and a
> value of a specific class.
>
> Suppose I want an Array of Pairs with keys as Str and values as Array of
> Str called "properties". And define it as a instance variable.Something o=
f
> the likes:
>
> has Pair[Str, Array[Str]] @!properties;
>
> Except this wont work.
>
>
> Best regards
> Mikkel
>

--000000000000fa2d850591d01deb
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">this lo=
oks like two questions-<div><br></div><div><div>typing Array contents - see=
=C2=A0<a href=3D"https://docs.perl6.org/language/list#___top">Typing</a></d=
iv></div><div>Syntax is &quot;my=C2=A0@bucket of TypedThings;&quot;</div><d=
iv><br></div><div>typing a Pair</div><div><br></div><div><div>&gt; my Pair[=
Str, Array[Str]] $x;</div><div>=3D=3D=3DSORRY!=3D=3D=3D Error while compili=
ng:</div><div>An exception occurred while parameterizing Pair</div><div>at =
&lt;unknown file&gt;:1</div><div>Exception details:</div><div>=C2=A0 =3D=3D=
=3DSORRY!=3D=3D=3D Error while compiling:</div><div>=C2=A0 Pair cannot be p=
arameterized</div><div>=C2=A0 ------&gt; my Pair[Str, Array[Str]]=E2=8F=8F =
$x;</div></div><div><br></div><div>Yep doesn&#39;t work! Must be a way, I d=
on&#39;t know it...</div><div><br></div><div><div><div dir=3D"ltr" class=3D=
"gmail_signature">-y<br></div></div><br></div></div></div></div></div><br><=
div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, Sep=
 5, 2019 at 5:34 AM Mikkel &lt;<a href=3D"mailto:mikkelsteen@gmail.com">mik=
kelsteen@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style=
:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr=
"><div>Hello</div><div><br></div><div>I am wondering whether it is possible=
 to define a Pair with a key and a value of a specific class.</div><div><br=
></div><div>Suppose I want an Array of Pairs with keys as Str and values as=
 Array of Str called &quot;properties&quot;. And define it as a instance va=
riable.Something of the likes:<br></div><div><br></div><div>has Pair[Str, A=
rray[Str]] @!properties;</div><div><br></div><div>Except this wont work.</d=
iv><div><br></div><div><br></div><div>Best regards</div><div>Mikkel<br></di=
v></div>
</blockquote></div>

--000000000000fa2d850591d01deb--
0
not
9/5/2019 3:38:33 PM
------U3WWYWG78VJEH1PSN7RXSVYM88UROQ
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

You can try defining a subset type a bit like this:

subset StrArrStrsPair of Pair where =2Ekey ~~ Str && =2Evalue ~~ Positiona=
l[Str];

Please be aware that the arrays have to be explicitly created with the typ=
e constant of Str for this to work=2E

On 5 September 2019 14:34:05 CEST, Mikkel <mikkelsteen@gmail=2Ecom> wrote:
>Hello
>
>I am wondering whether it is possible to define a Pair with a key and a
>value of a specific class=2E
>
>Suppose I want an Array of Pairs with keys as Str and values as Array
>of
>Str called "properties"=2E And define it as a instance variable=2ESomethi=
ng
>of
>the likes:
>
>has Pair[Str, Array[Str]] @!properties;
>
>Except this wont work=2E
>
>
>Best regards
>Mikkel

--=20
Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E
------U3WWYWG78VJEH1PSN7RXSVYM88UROQ
Content-Type: text/html;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body>You can try defining a subset type a bit like this=
:<br><br>subset StrArrStrsPair of Pair where =2Ekey ~~ Str &amp;&amp; =2Eva=
lue ~~ Positional[Str];<br><br>Please be aware that the arrays have to be e=
xplicitly created with the type constant of Str for this to work=2E<br><br>=
<div class=3D"gmail_quote">On 5 September 2019 14:34:05 CEST, Mikkel &lt;mi=
kkelsteen@gmail=2Ecom&gt; wrote:<blockquote class=3D"gmail_quote" style=3D"=
margin: 0pt 0pt 0pt 0=2E8ex; border-left: 1px solid rgb(204, 204, 204); pad=
ding-left: 1ex;">
<div dir=3D"ltr"><div>Hello</div><div><br></div><div>I am wondering whethe=
r it is possible to define a Pair with a key and a value of a specific clas=
s=2E</div><div><br></div><div>Suppose I want an Array of Pairs with keys as=
 Str and values as Array of Str called "properties"=2E And define it as a i=
nstance variable=2ESomething of the likes:<br></div><div><br></div><div>has=
 Pair[Str, Array[Str]] @!properties;</div><div><br></div><div>Except this w=
ont work=2E</div><div><br></div><div><br></div><div>Best regards</div><div>=
Mikkel<br></div></div>
</blockquote></div><br>-- <br>Sent from my Android device with K-9 Mail=2E=
 Please excuse my brevity=2E</body></html>
------U3WWYWG78VJEH1PSN7RXSVYM88UROQ--
0
timo
9/5/2019 4:37:18 PM
Reply: