On 9/14/05, Juerd <[EMAIL PROTECTED]> wrote: > Instead, if you don't want something to coerce, be explicit: > $foo.does(Blah) or fail;, or even: $foo.isa(Blah) or fail;.)
We've been thinking of changing .isa to something longer, or a method on .meta, because it's a notion that is often misused. Use .does instead; that's what you mean anyway (unless you're snooping around the guts of an object). > 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? > Why not see "bare" types as functions that create context? We'd then > have Int $num, Int($num), and automatically, $num.Int. All are easy to > recognise because of the capital I. You realize that those functions would all be the identity map with various expectations on their input. That's okay, it's just an interesting notion. > Is this weird syntax? Perhaps so, but we've known it from undef for > ages. undef without arguments is just undef, but when you give it > arguments, it suddenly actually *does* something. > > undef($foo) makes $foo undef, undef() just returns undef. Except we changed that because it was biting people: undef is null-ary and represents the undefined value; undef $foo is illegal undefine($foo) is mandatory unary, and always undefines its argument > Compare with: > > Int($foo) makes $foo Int, Int() just returns ::Int. That bugs me a little. But it's a bug I could get used to pretty quickly I reckon. I just wonder what kind of role coercion plays in the larger scheme of things. Does coercing to a Str work with anything that has a stringify operation (conversely, is ~ just a Str context applicator?)? If a parent class defines a coercion operation, do you get it too (and what are the implications of that)? What role does coercion play in multimethod dispatch? I can't seem to map the notion of coercion into my world model, so I'd personally like to see a proposal that covers these questions from someone who can map it into his world model. I'll bash it to pieces of course, but it'd be good to have somewhere to start. :-) Luke