Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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.


Comment on Re: Passing Str or undef ?
Select or Download Code
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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2015-10-09 02:20 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (232 votes), past polls