Sponsored Link •
|
Summary
In a recent discussion Kresimir Cosic said the following thing to me: "I think that subtyping a-posteriori is great.". When thinking about case classes ala Scala (which I believe was inspired by Haskell), I couldn't help but wonder, why not have case classes a-posteriori?
Advertisement
|
The following is lifted from http://scala.epfl.ch/intro/caseclasses.html:
Scala supports the notion of case classes. Case classes are regular classes which export their constructor parameters and which provide a recursive decomposition mechanism via pattern matching. Here is an example for a class hierarchy which consists of an abstract super class Term and three concrete case classes Var, Fun, and App.Okay, that is fine, but why not have something like the following :abstract class Term; case class Var(name: String) extends Term; case class Fun(arg: String, body: Term) extends Term; case class App(f: Term, v: Term) extends Term;
class Var { ... } class Fun { ... } class App { ... } casetype Term { Var; Fun; App; }AFAICT this method seems far more flexible and useful. I currently could use a case type, so I can't really see a good reason for not implementing it this way in Heron. Adding this to the languages is surprisingly simple.
Have an opinion? Readers have already posted 23 comments about this weblog entry. Why not add yours?
If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.
Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com. |
Sponsored Links
|