Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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

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
Node Status?
node history
Node Type: note [id://901380]
help
Chatterbox?
[Corion]: And this evening, I'm actually dusting off some old module of mine and bringing it up to the last version of the library I'm wrapping
[Lady_Aleena]: Updating things can be fun, if there is a better way to do it.
[Corion]: Lady_Aleena: Mostly, it's just housekeeping, but it inspires me about things I could do with it, so that's good ;)
[Lady_Aleena]: By the way, I stopped by to let someone know I'm still alive, though I haven't found anything to write in perl for a while now.
[Lady_Aleena]: I need inspiration.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-09-24 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (274 votes). Check out past polls.

    Notices?