Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Passing Str or undef ?

by stvn (Monsignor)
on Apr 26, 2011 at 15:35 UTC ( #901380=note: print w/ replies, xml ) Need Help??


in reply to Passing Str or undef ?

Corion actually answered the question, but only by guessing, so I will restate his answer but with some more details and certainty.

You have two choices here really, the first is a type union, which is written as Str | Undef and this basically says that the value can be either a String or Undefined. The second choice is the Maybe[`a] parameterized type, which would be written like this Maybe[Str]. This gives you basically the same thing as the type union but communicates the relationship differently by more explicitly saying "this *might* be undefined" not "this *can also* be undefined". My personal choice is always to do Maybe[`a] instead of the union in cases like these.

-stvn


Comment on Re: Passing Str or undef ?
Select or Download Code
Re^2: Passing Str or undef ?
by John M. Dlugosz (Monsignor) on Apr 27, 2011 at 11:13 UTC
    Yes, thanks. I like the apparent semantics better of Maybe.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://901380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-07-03 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls