When using the Types::Standard's InstanceOf in combination with Function::Parameters, the code using plain InstanceOf doesn't compile:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; { package My; sub new { bless {}, shift } } use Function::Parameters; use Types::Standard qw( InstanceOf ); fun validate(InstanceOf['My'] $m) { # <- Fails :-( say "object:", $m; } my $m = 'My'->new; validate($m);

The exact error message is

In fun validate: missing type name after '[' at 1.pl line 13.

It seems both the modules extend the parser somehow and they step on each other's toes.

Fortunately, it's pretty easy to fix that: you can prevent Function::Parameters from interpreting the InstanceOf before Types::Standard handles it by enclosing it into parentheses:

fun validate((InstanceOf['My']) $m) { # <- Works :-) # ~ ~

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re: Combining Function::Parameters with Type::Standard's InstanceOf
by etj (Priest) on Mar 18, 2022 at 16:49 UTC
      Your link showed me that I travelled there, too, to upvote both the question and answer. But I have since forgotten I'd done so, and more importantly, that I'd known the solution. Several days ago, I needed the solution again, but somehow wasn't able to google the answer, so had to reinvent it - and decided to post about it as it seemed non-trivial.
      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        Memory is a funny thing!