Re: subs and the type system

2020-07-21 Thread Theo van den Heuvel
Given that the signature is going to be more complex, it would be helpful if I do not need to repeat it for every member of the Walkable class. I tried using a constant to represent the signature so that I can create new Walkables without having to spell it out. Here is my code attempt (not

Re: subs and the type system

2020-07-20 Thread Tobias Boege
On Mon, 20 Jul 2020, Gianni Ceccarelli wrote: > Aside: > > ``(sub (Int $ --> Int) {}) ~~ Walkable`` is false, because > ``:(Int $ --> Int) ~~ :(Numeric $ --> Numeric)`` is false, which is > correct because function subtypes should be contravariant in the parameter > types and covariant in the

Re: subs and the type system

2020-07-20 Thread Gianni Ceccarelli
On Mon, 20 Jul 2020 14:00:33 +0200 Tobias Boege wrote: > You cannot write `Walkable ` in the signature of because the > combination of a type and the &-sigil apparently means that `` > should be Callable and return a Walkable. That's why I use the > $-sigil. Aha! That's the bit I got wrong,

Re: subs and the type system

2020-07-20 Thread Theo van den Heuvel
Thanks Gianni and Tobias, This is very helpful. One minor follow-up. If I define by signature like this: my $sgn-walkable = :(Numeric $n --> Numeric); I could not define Walkable subs like this, could I? my Walkable $crawlback = ... Thanks, Theo Tobias Boege schreef op 2020-07-20 14:00:

Re: subs and the type system

2020-07-20 Thread Tobias Boege
On Mon, 20 Jul 2020, Theo van den Heuvel wrote: > Hi gurus, > > after looking at the documentation on Sub, Signature and the raku type > system I find myself unable to constrain the types of functions in the way I > think I need. > > The situation: I have a function, let's call in 'walker',

Re: subs and the type system

2020-07-20 Thread Gianni Ceccarelli
On Mon, 20 Jul 2020 12:37:33 +0200 Theo van den Heuvel wrote: > The situation: I have a function, let's call in 'walker', whose first > parameter is a callback. > I wish to express that only callbacks with a certain Signature and > return type are acceptable. > Let's say the callback should

subs and the type system

2020-07-20 Thread Theo van den Heuvel
Hi gurus, after looking at the documentation on Sub, Signature and the raku type system I find myself unable to constrain the types of functions in the way I think I need. The situation: I have a function, let's call in 'walker', whose first parameter is a callback. I wish to express that