Author: larry
Date: Fri May 26 09:57:12 2006
New Revision: 9310

Modified:
   doc/trunk/design/syn/S06.pod

Log:
Clarifications of inner type from sam++.
Deployment of julian++ at 200605252055, 8`lb + 7`oz, 20`in.
   Ref: http://www.wall.org/cgi-bin/photo/index.cgi?mode=view&album=/pix/Julian


Modified: doc/trunk/design/syn/S06.pod
==============================================================================
--- doc/trunk/design/syn/S06.pod        (original)
+++ doc/trunk/design/syn/S06.pod        Fri May 26 09:57:12 2006
@@ -13,9 +13,9 @@
 
   Maintainer: Larry Wall <[EMAIL PROTECTED]>
   Date: 21 Mar 2003
-  Last Modified: 24 May 2006
+  Last Modified: 26 May 2006
   Number: 6
-  Version: 36
+  Version: 37
 
 
 This document summarizes Apocalypse 6, which covers subroutines and the
@@ -1405,14 +1405,20 @@
     my $spot of Dog;
 
 In either case this sets the C<of> property of the container to C<Dog>.
-Subroutines have a variant of the C<of> property, C<returns>, that
-sets the C<returns> property instead.  The C<returns> property specifies
-a constraint to be checked upon calling C<return> that, unlike the C<of>
-property, is not advertized as the type of the routine:
-
-    our Animal sub get_pet() {...}
-    sub get_pet() returns Animal {...}
-    sub get_pet() of Animal {...}
+
+Subroutines have a variant of the C<of> property, C<returns>, that sets
+the C<returns> property instead.  The C<returns> property specifies a
+constraint (or perhaps coercion) to be enforced on the return value (either
+by explicit call to C<return> or by implicit fall-off-the-end return).
+This constraint, unlike the C<of> property, is not advertised as the
+type of the routine.  You can think of it as the implicit type signature of
+the (possibly implicit) return statement.  It's therefore available for
+type inferencing within the routine but not outside it.  If no inner type
+is declared, it is assumed to be the same as the C<of> type, if declared.
+
+    sub get_pet() of Animal {...}      # of type, obviously
+    our Animal sub get_pet() {...}     # of type
+    sub get_pet() returns Animal {...} # inner type
 
 A value type on an array or hash specifies the type stored by each element:
 
@@ -1539,19 +1545,21 @@
 
 =head2 Return types
 
-On a scoped subroutine, a return type can be specified before or
-after the name.  We call all return types "return types", but distinguish
-two kinds of return type, the C<where> type from the C<of> type, because
-the C<of> type must be an "official" named type, while the C<where> type
-is merely applied as a constraint to what may be returned by the routine.
+On a scoped subroutine, a return type can be specified before or after
+the name.  We call all return types "return types", but distinguish
+two kinds of return type, the C<inner> type and the C<of> type,
+because the C<of> type is normally an "official" named type and
+declares the official interface to the routine, while the C<inner>
+type is merely a constraint on what may be returned by the routine
+from the routine's point of view.
 
+    our sub lay returns Egg {...}      # inner type
     our Egg sub lay {...}              # of type
-    our sub lay returns Egg {...}      # where type
     our sub lay of Egg {...}           # of type
     our sub lay (--> Egg) {...}                # of type
 
+    my sub hat returns Rabbit {...}    # inner type
     my Rabbit sub hat {...}            # of type
-    my sub hat returns Rabbit {...}    # where type
     my sub hat of Rabbit {...}         # of type
     my sub hat (--> Rabbit) {...}      # of type
 
@@ -1559,14 +1567,14 @@
 namespace (module, class, grammar, or package), as if it's scoped with
 the C<our> scope modifier. Any return type must go after the name:
 
-    sub lay returns Egg {...}          # where type
+    sub lay returns Egg {...}          # inner type
     sub lay of Egg {...}               # of type
     sub lay (--> Egg) {...}            # of type
 
 On an anonymous subroutine, any return type can only go after the C<sub>
 keyword:
 
-    $lay = sub returns Egg {...};      # where type
+    $lay = sub returns Egg {...};      # inner type
     $lay = sub of Egg {...};           # of type
     $lay = sub (--> Egg) {...};                # of type
 
@@ -1581,12 +1589,12 @@
 The return type may also be specified after a C<< --> >> token within
 the signature.  This doesn't mean exactly the same thing as C<returns>.
 The C<of> type is the "official" return type, and may therefore be
-used to do type inferencing outside the sub.  The C<where> type only
+used to do type inferencing outside the sub.  The C<inner> type only
 makes the return type available to the internals of the sub so that
 the C<return> statement can know its context, but outside the sub we
 don't know anything about the return value, as if no return type had
 been declared.  The prefix form specifies the C<of> type rather than
-the C<where> type, so the return type of
+the C<inner> type, so the return type of
 
     my Fish sub wanda ($x) { ... }
 
@@ -1598,7 +1606,7 @@
 
     my sub wanda ($x) returns Fish { ... }
 
-It is possible for the C<of> type to disagree with the C<where> type:
+It is possible for the C<of> type to disagree with the C<inner> type:
 
     my Squid sub wanda ($x) returns Fish { ... }
 
@@ -1606,7 +1614,9 @@
 
     my sub wanda ($x --> Squid) returns Fish { ... }
 
-It's not clear why you'd want to lie to yourself like that, though.
+This is not lying to yourself--it's lying to the world.  Having a
+different inner type is useful if you wish to hold your routine to
+a stricter standard than you let on to the outside world, for instance.
 
 =head1 Properties and traits
 
@@ -1650,7 +1660,7 @@
 
 =item C<returns>/C<is returns>
 
-The C<where> type constraint that a routine imposes in its return value.
+The C<inner> type constraint that a routine imposes in its return value.
 
 =item C<of>/C<is of>
 

Reply via email to