develooper Front page | perl.perl5.porters | Postings from November 2019

Re: Type and Value Constraints and Coercions

Thread Previous | Thread Next
November 29, 2019 17:12
Re: Type and Value Constraints and Coercions
Message ID:
Dave Mitchell <> wrote:
:=item isa <Class::Name>
:    sub f ($x isa Class::name)
:is roughly shorthand for
:    sub f ($x where    defined $_
:                    && ref($_)
:                    && $_->isa('Class:name'))
:Although if Paul Evan's 'isa' infix keyword is accepted into core, then
:the signature 'isa' trait should become exactly shorthand for:
:    sub f ($x where $_ isa Class::Name) { ... }
:and any rules regarding whether the class name is quoted and/or
:has a trailing '::' should be the same.

Will this permit '$x isa $expr' (or does it depend on whether we get
Paul's keyword)? If so, is the expression resolved to a constant at
compile time or at runtime?

:=item is <constraint-type-name>
:This means that (for example), if a Math::BigInt value is passed as
:the argument for $i, the resulting parameter will just be a plain int
:and any extra data or behaviour will have been lost.

I use bigints a lot, and most functions that don't check their params
too carefully work just fine. I'd love to see an easy way to bypass
the coercion when I know what I'm doing, but fear I won't get one.

The majority don't know or care about bigints, so I anticipate that
Int declarations will get sprayed about liberally primarily as a means
of writing more self-documenting code.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About