Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Passing Str or undef ?

by stvn (Monsignor)
on Apr 26, 2011 at 15:35 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://901380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found