Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How are types related to classes and roles?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 26 - 35 of 35 - Collapse all  -  Translate all to Translated (View all originals) < Older 
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Thomas Sandlaß  
View profile  
 More options Feb 28 2005, 12:45 pm
Newsgroups: perl.perl6.language
From: Thomas.Sandl...@orthogon.com (Thomas Sandlaß)
Date: Mon, 28 Feb 2005 18:45:38 +0100
Local: Mon, Feb 28 2005 12:45 pm
Subject: Re: How are types related to classes and roles?
HaloO Aaron,

you wrote:
> Um... I think you're thinking of operator overloading, which in Parrot
> actually does use the MMD facility under the hood, but MMD is nominally
> a separate facility. You should glance at the PDDs, as they have far
> more detail than I'm aware of.

You mean the ones in the docs/pdd directory of the Parrot CVS?
There's nothing about MMD.

What I mean is mails from Leo like these from December 2004:
http://groups-beta.google.com/group/perl.perl6.internals/msg/1579a27d...
http://groups-beta.google.com/group/perl.perl6.internals/msg/de8a10bd...

The opcodes for 'callmethod_MMD_3_sig "func"' and 'callmethod_MMD_n "func", n'
are simply not there yet, right? Neither are opcodes for making entries into
the dispatch tables/trees. Does Perl 6 actually need predicate dispatch?
After all we can specify closures and smart matches in the 'where' of multi
method parameter types!

Sorry, if this is the wrong list for discussing these Parrot details.
--
TSa (Thomas Sandlaß)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Sherman  
View profile  
 More options Feb 28 2005, 12:06 pm
Newsgroups: perl.perl6.language
From: a...@ajs.com (Aaron Sherman)
Date: Mon, 28 Feb 2005 12:06:32 -0500
Local: Mon, Feb 28 2005 12:06 pm
Subject: Re: How are types related to classes and roles?

On Mon, 2005-02-28 at 10:34, Thomas Sandlaß wrote:
> Am I missing something, but the only thing I've figured out so far is that
> Parrot uses ternary MMD for its builtin binary ops like ADD, MUL, OR, etc.
> They are ternary to prevent a final copy or conversion of the result to the
> target register. Where is the general MMD mechanism?

Um... I think you're thinking of operator overloading, which in Parrot
actually does use the MMD facility under the hood, but MMD is nominally
a separate facility. You should glance at the PDDs, as they have far
more detail than I'm aware of.

> Will the Perl 6 MMD be directly implemented in Parrot or on top of it?
> I guess Parrot needs to do it for language interoperability, right?

I would expect so, yes.....

--
☎ 781-324-3772
✉ a...@ajs.com
http://www.ajs.com/~ajs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Sherman  
View profile  
 More options Feb 28 2005, 1:34 pm
Newsgroups: perl.perl6.language
From: a...@ajs.com (Aaron Sherman)
Date: Mon, 28 Feb 2005 13:34:11 -0500
Local: Mon, Feb 28 2005 1:34 pm
Subject: Re: How are types related to classes and roles?

On Mon, 2005-02-28 at 12:45, Thomas Sandlaß wrote:
> Sorry, if this is the wrong list for discussing these Parrot details.

Yeah, you really want to be in p6i, not p6l. These guys think a Parrot's
just a bird that says funny things and sits on a pirate's shoulder ;-)

PS: http://cpan.uwinnipeg.ca/htdocs/parrot/mmd.html

--
☎ 781-324-3772
✉ a...@ajs.com
http://www.ajs.com/~ajs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leopold Toetsch  
View profile  
 More options Feb 28 2005, 1:12 pm
Newsgroups: perl.perl6.language
From: l...@toetsch.at (Leopold Toetsch)
Date: Mon, 28 Feb 2005 19:12:59 +0100
Local: Mon, Feb 28 2005 1:12 pm
Subject: Re: How are types related to classes and roles?

Thomas Sandlaß <Thomas.Sandl...@orthogon.com> wrote:
> Am I missing something, but the only thing I've figured out so far is that
> Parrot uses ternary MMD for its builtin binary ops like ADD, MUL, OR, etc.

actually binary, dispatch is based on (left, right) operands.

> They are ternary to prevent a final copy or conversion of the result to the
> target register. Where is the general MMD mechanism?

No. The destination has currently to exist. But I'll very likely put in
variants that create the destination.

Currently a static 2-dimensional MMD table is used. This will be
replaced by a dynamic lookup and caching.

> Will the Perl 6 MMD be directly implemented in Parrot or on top of it?
> I guess Parrot needs to do it for language interoperability, right?

Yep.

leo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leopold Toetsch  
View profile  
 More options Feb 28 2005, 1:20 pm
Newsgroups: perl.perl6.language
From: l...@toetsch.at (Leopold Toetsch)
Date: Mon, 28 Feb 2005 19:20:06 +0100
Local: Mon, Feb 28 2005 1:20 pm
Subject: Re: How are types related to classes and roles?

Thomas Sandlaß <Thomas.Sandl...@orthogon.com> wrote:
> The opcodes for 'callmethod_MMD_3_sig "func"' and 'callmethod_MMD_n
> "func", n' are simply not there yet, right?

No. The problem is that at function call time there is no indication
that a MMD subroutine should be called. So Parrot will just do a full
MMD search, if no other indication is there that it's just a plain
subroutine.

Another problem is language interoperbility. As e.g. python has no
syntax for MMD, above opcodes would be useless - Python wouldn't be
able to call any of the MMD builtins.

leo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Sandlaß  
View profile  
 More options Mar 4 2005, 3:12 pm
Newsgroups: perl.perl6.language
From: Thomas.Sandl...@orthogon.com (Thomas Sandlaß)
Date: Fri, 04 Mar 2005 21:12:10 +0100
Local: Fri, Mar 4 2005 3:12 pm
Subject: Re: How are types related to classes and roles?
HaloO Larry,

you wrote:
> One can view the auto-coercion as a form of MMD if you allow the
> autogeneration of any necessary coercion methods.  However, it's not
> exactly a coercion to Str or Int--it's more like promotion to a Scalar
> that is able to pretend it is either Str or Int.  Or you can view it
> as a kind of cached conversion.  The ~ operator doesn't demand the
> Str type--it only demands something which can fulfill the string role.

I don't understand which role roles play :)
Since they are not instanciable they are well suited to be interpreted
as (abstract) types in other languages or type generators.
A very interesting thing is that they can be arranged into a lattice
if any() and all() junctions on roles give their lubs and glbs.
So having e.g. two roles A and B

role A { ... }
role B { ... }

we get first the rhomb shaped Hasse Diagram:

                 A|B         lub (lowest upper bound)
                /   \
               /     \
              A   0   B
             / \     / \
            /   \   /   \
           /     A&B     \   glb (greatest lower bound)
          /  1  /   \  2  \
         /     /  3  \     \

In the cones below A and B respectively are classes that do A or B:

class X does A { ... }
class Y does B { ... }

The roles themself beeing the least member of these classes---uninstanciable "pure"
behaviour. The intersection type/role A&B is multiple inheritance (or is that
"roling"?):

class Z does A does B { ... }
class Z does A & B { ... }  # valid syntax?

The junctive classes in area 0 are special because they need to do special
stuff *between* A and B. The prime example for this is

class Scalar does Str | Int { ... }

This syntax can be seen as some kind of superclassing or superroling:
a Scalar can go where no plain Str or Int can go!
BTW, what does a class that is specified without a role?
I think it would do the lub of of roles: Any. Right?

The above assumes that type checking and MMD is on behave of roles
and that classes are used for single dispatched methods only. So an
implementor of Scalar has to do some extra work for the any-junctive
behaviour, like the multiroling implemention has to resolve potential
conflicts between composed roles. Unfortunately I have no clear idea
of what these extras are and to what extent they can be enforced by
the compiler.  Typically a class like Scalar mostly brings in coercions
and mixed multi methods, i.e. they are a bit less restricted in what multis
they are allowed to define---if of course Perl 6 is using implementation
side type checks at all.

> I think the best thing we can do here is to encourage a culture in
> which people recognize the fundamental difference between extending
> a base class and constraining a subtype, and learn to use composition
> and delegation where appropriate instead of inheritance.  That's why
> we've given different keywords to all those concepts.  It's a matter
> of giving people the mental tools to think straighter.

Does this toolset support F-bounded polymorphism? And how is its syntax?
To illustrate this question I've rephrased the examples and adjusted the
explainations from the Cecil Manual in Perl 6 below. The original can be
found at

http://www.cs.washington.edu/research/projects/cecil/www/Vortex-Three...

This subsection describes an example of advanced use of the Cecil type
system, F-bounded polymorphism. As we will see, no special support for
this powerful idiom is needed in the type system -- it is made
possible by allowing constraints to be recursive, whereby a type
variable can appear in its own bound.

For our first example, let us consider an abstract object ordered and
a binary method >. A binary method is a method that expects two
arguments of similar types; the > method can be applied, for example,
to two numbers or two strings, but not a string and a number. We would
like to define this method once, in the Ordered role, and have other
classes, such as Num and Str, inherit it. The simplest way to
achieve it seems to be as follows:

role Ordered
{
    multi method infix:«<=» ( Ordered $x, Ordered $y ) returns bool
    {
      ...
    }
    multi method infix:«>» ( Ordered $x, Ordered $y ) returns bool
    {
       return not $x <= $y
    }

}

class Num does Ordered { ... }
class Str does Ordered { ... }

This code, however, leads to an undesirable effect. Since > and <= are
defined for Ordered and Num and Str are its subclasses, we are
required to write implementations of <= to compare a num and a string,
which we may not want. To avoid mixing of subclasses of ordered, we
can apply F-bounded polymorphism as follows:

role Ordered[ type ::T where { T <= Ordered[T] } ]    # op '<=' defined for types?
role Ordered[ type ::T where { T does Ordered[T] } ]
role Ordered[ ::T does Ordered[T] ]  # operator 'does' allowed here?
role Ordered[ Ordered[::T] ::T ]
role Ordered[ Ordered[T] ::T ]   # too short, because T is not known before ::T?
{
    multi method infix:«<=» ( T $x, T $y ) returns bool
    {
      ...
    }
    multi method infix:«>» ( T $x, T $y ) returns bool
    {
       return not $x <= $y
    }

}

class Num does Ordered[Num] { ... }
class Str does Ordered[Str] { ... }

class Scalar does Ordered[Num|Str] { ... }  # Perl 6 actually has that

Now method > can be instantiated with Num for T (because the
instantiated constraint Num <= Ordered[Num] can be solved: there is a
corresponding declaration in the program) or with Str for T, but
cannot with Str|Num for T (which would be required in order to
compare a Num and a Str).

With this scheme, in addition to defining binary methods itself,
ordered and all its subtypes can inherit binary methods from other
objects, for example:

role Comparable[ type ::T where { T <= Comparable[T] } ]
role Comparable[ ::T does Comparable[T] ]
role Comparable[ Comparable[::T] ::T ]
role Comparable[ Comparable[T] ::T ]
{
    multi method infix:«==» ( T $x, T $y ) returns bool
    {
      ...
    }
    multi method infix:«!=» ( T $x, T $y ) returns bool
    {
       return not $x == $y
    }

}

role Ordered[ type ::T ] does Comparable[T]
{
    multi method infix:«<=» ( T $x, T $y ) returns bool
    {
      ...
    }
    multi method infix:«>» ( T $x, T $y ) returns bool
    {
       return not $x <= $y
    }

}

Moreover, Num can have subtypes, such as Int or Float, which can be
compared with each other, but not with Str or its subtypes:

class Int   is Num {...}
class Float is Num {...}
3 != 3.14  # legal

Sorry if this is too brain-dead!
--
TSa (Thomas Sandlaß)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chromatic  
View profile  
 More options Mar 4 2005, 3:36 pm
Newsgroups: perl.perl6.language
From: chroma...@wgz.org (Chromatic)
Date: Fri, 04 Mar 2005 12:36:04 -0800
Local: Fri, Mar 4 2005 3:36 pm
Subject: Re: How are types related to classes and roles?

On Fri, 2005-03-04 at 21:12 +0100, Thomas Sandlaß wrote:
> The roles themself beeing the least member of these classes---uninstanciable "pure"
> behaviour. The intersection type/role A&B is multiple inheritance (or is that
> "roling"?):

I don't understand the question (I don't recognize the words "lubs" or
"glbs", for example), but I don't think this has anything at all to do
with multiple inheritance.

Generalizing types on a class based on inheritance is micromanagement.
It cares too much about how polymorphism works.  This is why putting
abstract, uninstantiable classes in languages that don't support
multiple inheritance is a cure worse than the disease -- it recognizes
that there's a problem with forcing all type equivalence to go through
inheritance, but it adds a second type system alongside the first and
classes again have to know too many details about how one particular
class marks its equivalence.

I don't think that roles are necessarily unsubstantiable; class and role
names should occupy the same namespace.  It ought to be possible to have
class A with a particular set of methods and class B with a set of
methods of the same name and similar enough semantics for the entire set
of behavior of those methods and be able to mark class B as performing
the A role and to be able to pass B objects into code that asks for A
objects and have things just work without A or B necessarily having to
share code and definitely without them being related to each other in
any sort of inheritance relationship.

Maybe there's not enough behavior in a role to make it a full class, but
there's enough behavior that it's useful across classes horizontally and
it deserves its own name.

Maybe that's not helpful, but I did warn that I didn't understand the
question!

-- c


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Sandlaß  
View profile  
 More options Mar 4 2005, 4:33 pm
Newsgroups: perl.perl6.language
From: Thomas.Sandl...@orthogon.com (Thomas Sandlaß)
Date: Fri, 04 Mar 2005 22:33:26 +0100
Local: Fri, Mar 4 2005 4:33 pm
Subject: Re: How are types related to classes and roles?
HaloO chromatic,

you wrote:
> I don't understand the question (I don't recognize the words "lubs" or
> "glbs", for example), but I don't think this has anything at all to do
> with multiple inheritance.

Sorry, that was given only in the picture:
  lub = least upper bound (also known as supremum)
  glb = greatest lower bound (infimum)
see e.g. http://www-rohan.sdsu.edu/~gawron/mathling/poset/posets.pdf

> I don't think that roles are necessarily unsubstantiable; class and role
> names should occupy the same namespace.

That is the case in Perl 6, isn't it? Makes sense to me. And subs are
in the same name space as well, right?

>  It ought to be possible to have
> class A with a particular set of methods and class B with a set of
> methods of the same name and similar enough semantics for the entire set
> of behavior of those methods and be able to mark class B as performing
> the A role

Hmm, like that?

class A { ... }
class B does A { ... }

> and to be able to pass B objects into code that asks for A
> objects and have things just work without A or B necessarily having to
> share code and definitely without them being related to each other in
> any sort of inheritance relationship.

Types/roles and classes form different hierarchies. The former is
partially ordered by checking the does relation the latter by checking
the isa relation. By letting classes do roles you create families
of objects that do a certain behaviour but don't share the same
implementation. On the other hand areas of code happen to require
certain functionality. The entity that checks that they are met is the
typechecker. My question basically is about how you declare your
intensions so that the type checker can DWYM. E.g. if you were to specify
comparability so that you are just comparing the right things.

> Maybe there's not enough behavior in a role to make it a full class, but
> there's enough behavior that it's useful across classes horizontally and
> it deserves its own name.

My question is not about completeness of roles versus classes but about
how the Perl 6 type system shall work. Or better which assertions it is supposed
to make about code. This is very usefull when it comes to programming in the
large and of course it allows good optimization if the typecheker can proof
e.g. that no dynamic dispatch is needed because there is only one statically
determinable match anyway.

> Maybe that's not helpful, but I did warn that I didn't understand the
> question!

I'm struggling, too.
--
TSa (Thomas Sandlaß)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Sandlaß  
View profile  
 More options Mar 4 2005, 5:13 pm
Newsgroups: perl.perl6.language
From: Thomas.Sandl...@orthogon.com (Thomas Sandlaß)
Date: Fri, 04 Mar 2005 23:13:07 +0100
Local: Fri, Mar 4 2005 5:13 pm
Subject: Re: How are types related to classes and roles?

I wrote:

>                 A|B         lub (lowest upper bound)
>                /   \
>               /     \
>              A   0   B
>             / \     / \
>            /   \   /   \
>           /     A&B     \   glb (greatest lower bound)
>          /  1  /   \  2  \
>         /     /  3  \     \

I was a bit lax in explaining my picture and it's relation
to type junctions. A, B, A|B and A&B are roles. In the areas
0..3 you find classes that do the roles in the surrounding cone.
They are not related to each other by subtyping!

Outside are the classes and roles none(A,B). The subtype relation
is vertical with more general towards the top. I'm a bit unsure
what the one-junction A^B really means but the classes that do
it are located in area 1+2 ;)

I hope that helps.
--
TSa (Thomas Sandlaß)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Sandlaß  
View profile  
 More options Mar 7 2005, 12:16 pm
Newsgroups: perl.perl6.language
From: Thomas.Sandl...@orthogon.com (Thomas Sandlaß)
Date: Mon, 07 Mar 2005 18:16:21 +0100
Local: Mon, Mar 7 2005 12:16 pm
Subject: Re: How are types related to classes and roles?

HaloO,

another self-reply :)

I've added a little hack that classifies strings
into these areas 0 to 3 to illustrate my idea of
a type lattice on which composes the background
of the Perl 6 Type System. Pattern matching and
type systems are related but the question for
Perl 6 is: how exactly?

The topmost type Any has a very nice mnemonic: it's
the any-junction of all types that have no direct
supertype---their lub. Likewise there could be a None
that is the none-junction of all types that have no
subtype---their glb.

This means the Any actually depends on the loaded
program. If it only uses e.g. the unrelated types
A, B and C then Any is A|B|C. Likewise for programs
that implicitly handle strings and do numerics one
gets Any = Str|Num.

BTW, are Num and Int distinct or is there a
relation: Int is/does Num?

Regards,
--
TSa (Thomas Sandlaß)

  p6-type-match.pl
1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages < Older 
« Back to Discussions « Newer topic     Older topic »