I'm willing to bracket mutability and make it syntactically painful if need be. That's why I'm not too concerned about it right now.
I understand that people keep saying there is a theoretical problem somewhere. I'm curious as to where there is a practical problem — what specific code is problematic? List.cons is typed as: 'a -> list('b) -> list('a|'b) And List.first is typed as: list('a) -> 'a So, yes, if you add different types to the same list, and you want to use an API beyond overlapping APIs on the types, then you're going to have to do a match to extract the type, even if you "know" what the right answer should be. Is that the big issue which everyone is freaking out about? ~~ 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 12:24 PM, Brian Hurt <bhur...@gmail.com> wrote: > On Wed, Aug 10, 2011 at 7: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? >> > > You get co-/contra-variance any time you have subtyping- any time you > have a situation where all B's are also A's, but not all A's are B's. > So if A is the type of objects having methods foo and bar, and B is > the type of objects having foo, bar, and baz methods (with foo and bar > having the same signatures as A's foo and bar), then B is a subtype of > A. The fact that the subtyping relationship was introduced > structurally or nominally is irrelevant. > > In terms of theory, there is no difference between structural typing > and nominal typing. Introducing a new structural type is the > equivalent to introducing a new uniquely named nominal interface, and > having the interface applied to all applicable types. In practice, > introducing that new interface and applying it to all necessary > classes ranges in difficulty from annoying to impossible, so in > practice there is a huge difference (and structural aka duck typing > wins big time). > >> Specifically, can you show a situation where contra- or co- variance >> are problems when using structural typing without mutable data >> structures? >> > > What are the types for List.cons and List.first? Or Map.add and Map.get? > > And you're going to have mutable containers, even if they're only ref > cells. Even Haskell has MVars and TVars and the like. > > Brian > > -- > 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.