The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
A-Posteriori Subtyping and Case Classes
by Christopher Diggins
January 26, 2006
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.
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;
Okay, that is fine, but why not have something like the following :
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.

Talk Back!

Have an opinion? Readers have already posted 23 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

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.

This weblog entry is Copyright © 2006 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us