On Wed, 14 Sep 2005, Luke Palmer wrote:

my Int $int = $num;

Explicit coercion, however, isn't done with context: it is done with the
.as() method: $num.as(Int). I think that's weird.

Not to mention the fact that you might have put an Int there for
typechecking purposes instead of coersion purposes, and you actually
want it to die if $num is a string.  Hmmm, how do we get both at once?

My 2 cents ...

Coercion and typechecking need to be fairly distinguishable for reading and writing code, as they're very different things.

I for one like "my Int $int" as type checking, meaning it'll die if not given an int, and some sort of method/function for coercion, presumably the above-mentioned "as(Int)".

The default should be type-checking is always strict, and coercion is never automatic, IMO. Otherwise it's just not that useful, because you always have to remember the various auto-coercion rules.

Of course, for people who think that's "intuititive", there could be some sort of "use coercion" pragma, maybe something like:

 use coercion Num => Int uses .int,
              String => Int uses .numerify_if_looks_like_number,
              Date => String uses .date;

Of course I'm pulling the syntax/API from my nether regions.


-dave

/*===================================================
VegGuide.Org                        www.BookIRead.com
Your guide to all that's veg.       My book blog
===================================================*/

Reply via email to