On Wed, Feb 16, 2005 at 11:02:25PM -0600, Patrick R. Michaud wrote:
: On Tue, Feb 15, 2005 at 11:03:09PM -0800, Larry Wall wrote:
: > On Wed, Feb 16, 2005 at 02:29:36PM +0800, Autrijus Tang wrote:
: > : Just a quick question.  The prettyprinter of Pugs (the thing that
: > : handles the ".perl" method) currently prints out boolean true and
: > : false as #t and #f, which is obviously not correct.
: > : 
: > :     pugs> (1 > 2, 2 > 1)
: > :     (#f, #t)
: > : 
: > : What should I do, though?  Inventing two primitives, "true" and
: > : "false"?  Or is there a way to annotate values with types, similar
: > : to Haskell's "::" construct?
: > : 
: > :     pugs> (1 > 2, 2 > 1)
: > :     (0 as Bool, 1 as Bool)
: > 
: > The latest S12 has it as bool::true and bool::false.  
: 
: S03 still indicates that boolean operators return "a standard
: boolean value (either 1 or 0)".  Are we continuing with 1 and 0
: as the standard boolean values, or bool::true and bool::false?

Yes.  :-)

True boolean values are bits.  bool::true and bool::false are just
convenient names for certain values of small, 1-bit integers.

: More to the point, what's the return type of something like
: &infix:ï>ï ?

Type "bit", which is just a rather small subtype of int.  The bit type
is really an alias for "uint1".  If you're asking what it actually
returns internally, it's perfectly fine to store a tiny integer subtype
into a normal int.

So to stop evading your question, it returns 0 or 1.  :-)

But I buy into the whole subtype/type distinction that Ada made.
A compiler is always free to store a subtype value in a type location.
You can keep a uint4 in an int.  It's only when you assign an int value
into a uint4 location that you have to worry about the subtype constraints.
(And the compiler is free to optimize the subtype storage based on
the constraint, so an array of bits really can be stored compactly.)

But boolean context in Perl 6 doesn't enforce that it gets a uint1
subtype.  It only enforces that it requires a type that knows how to
play the boolean role, either because it has the .bit method, or because
it's some low-level type we've hardwired to bypass the .bit method for
speed.

Larry

Reply via email to