What does "subtyping" mean in a prototype language with structural types? There is no such thing as a "parent" or "child" type, so the type hierarchy context — the only context where "subtyping" means something to me — doesn't exist.
Consider these two records: let x = [ add: { a, b -> a + b }, subtract: { a, b -> a - b } ] let y = [ add: { a, b -> a + b }, multiply: { a, b -> a * b } ] Which is the parent? Which is the child? If you do something like this: let xs = x :: [x] let ys = y :: [y] let xys = x :: y :: [x] Then the types are all well-defined: list of things like x, list of things like y, list of things like x-or-y. You can't turn "xys" into a list of xs or a list of ys, because it's neither. The only place where I've found subtyping issues is with code like this: let foundXs = xys.findAll { it -> it.like(x) } (Where "like" is "structurally identical to".) The list "foundXs" is now a list of "x"-like structures, even though the type is a list of "x-or-y"-like structures. But that—like a couple of the similar cases I've encountered—are what *should be* match statements being dropped in strange places, usually because of an OOP accent in the programmer. And it's easy to define a properly-typed findAllLike, if you really wanted to stick to it: let findAllLike = {list,type -> list match { case () => () case (a:type) :: rest => a::findAllLike(rest, type) case a::rest => findAllLike(rest) }} So it doesn't seem to be a problem to reject importing the idea of "casting up", which is good since it doesn't even really mean anything anyway in this context. ~~ Robert. Love Your Enemy: A Campaign to Regain Human Dignity Through Nonviolence http://www.mettacenter.org/mc/projects/love-your-enemy On Wed, Aug 10, 2011 at 11:47 AM, John Cowan <johnwco...@gmail.com> wrote: > On Wed, Aug 10, 2011 at 10:29 AM, Robert Fischer > <smokejumpe...@gmail.com> wrote: > >> Can you define "contra-" and "co-" variance for me in the context of >> structural (not nominal) typing? > > Whether a type system is structurally or nominally typed is orthogonal > to whether it has subtyping. Algol 68 records, which are structural > types, have no subtypes; but Go interface types, which are also > structural types, do have subtypes. The co- and contravariance > problem arises wherever there are static types with subtyping. > > -- > GMail doesn't have rotating .sigs, but you can see mine at > http://www.ccil.org/~cowan/signatures > > -- > You received this message because you are subscribed to the Google Groups > "JVM Languages" group. > To post to this group, send email to jvm-languages@googlegroups.com. > To unsubscribe from this group, send email to > jvm-languages+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/jvm-languages?hl=en. > > -- You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to jvm-languages@googlegroups.com. To unsubscribe from this group, send email to jvm-languages+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.