develooper Front page | perl.perl6.language | Postings from July 2010

r31735 -[spec] Say a bit about Numeric operators and Bridge.

Thread Next
From:
pugs-commits
Date:
July 16, 2010 11:39
Subject:
r31735 -[spec] Say a bit about Numeric operators and Bridge.
Message ID:
20100716183934.12014.qmail@feather.perl6.nl
Author: colomon
Date: 2010-07-16 20:39:33 +0200 (Fri, 16 Jul 2010)
New Revision: 31735

Modified:
   docs/Perl6/Spec/S32-setting-library/Numeric.pod
Log:
[spec] Say a bit about Numeric operators and Bridge.

Modified: docs/Perl6/Spec/S32-setting-library/Numeric.pod
===================================================================
--- docs/Perl6/Spec/S32-setting-library/Numeric.pod	2010-07-16 18:19:27 UTC (rev 31734)
+++ docs/Perl6/Spec/S32-setting-library/Numeric.pod	2010-07-16 18:39:33 UTC (rev 31735)
@@ -56,10 +56,16 @@
 
 C<Numeric> is a role for everything that's a scalar number. So C<Num>, C<Int>,
 C<Rat>, C<Complex> and other numeric types do that role. However it is an
-abstract interface, so C<$number.WHAT> will never return C<Numeric>. Users who
-provide their own scalar numeric types are encouraged to implement the
-C<Numeric> role.
+abstract interface, so C<$number.WHAT> will never return C<Numeric>. 
 
+Users who provide their own scalar numeric types are encouraged to implement the
+C<Numeric> role.  It is intended that such types such support the basic arithmetic
+operators to the extent possible, as well as C<==>.  In addition, it is hoped that
+comparison operators will at least return consistent results, even if there is no
+sensible mathemtical ordering of your type.  That allows functions like sort to 
+not choke and die if they are handed a value of your type.  (See also the C<Real>
+role for scalar numeric types that represent real numbers.)
+
 The following are all defined in the C<Numeric> role:
 
 C<Numeric> provides some constants in addition to the basic
@@ -201,6 +207,15 @@
 a real scalar number (i.e. neither C<Complex> nor vector-like). For example
 C<Num>, C<Int>, C<Bool> and C<Rat> implement the C<Real> role.
 
+Users who provide their own scalar real numeric types are encouraged to implement the
+C<Real> role.  Because all C<Real> types are well-ordered, it is desirable that any two
+C<Real> types be mutally compatiable, even if they are not aware of each other.  The
+current proposal requires you to define a C<Bridge> method in your C<Real> type, which
+converts your type into a neutral C<Real> type by restating it in terms of the fundamental
+PerlĀ 6 types and calling C<Bridge> on them.  This then makes the default C<Real> methods
+and operators all work with your C<Real> type.  While the name of this method may changed,
+it is hoped that something like this will remain in the spec.
+
 =over
 
 =item Complex


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About