[isabelle-dev] ADTs in Scala

Makarius makarius at sketis.net
Thu Apr 12 21:14:31 CEST 2012


Dear all,

some year ago, I've complained about the lack of good old abstract 
datatypes in Scala.  Some of the reactions were that I was asking for 
wrong things in an "object-oriented" environment, pointing to classic 
literature about that.

In the meantime, I've managed to do it in a reasonably simple way, e.g. 
see 
http://isabelle.in.tum.de/repos/isabelle/file/83294cd0e7ee/src/Pure/General/graph.scala

   object Graph
   {
     // public operations to create ADT instances
   }

   final class Graph[Key, A] private(rep: SortedMap[Key, (A, (SortedSet[Key], SortedSet[Key]))])
   {
     // implementation with access to rep
   }

The main thing is the "private" in this odd position, which is Odersky's 
way to make the constructor private, but the keep the type itself public. 
This detail seems to have been forgotten in Java -- in fact in a recent 
talk some Java guru admitted that -- which was also my starting point to 
google for "private constructor" to find the above solution.

Moreover, the "final" prevents unexpected behaviour from class extensions. 
It is a concession to the remaining ooddities of the platform.

Now after 25 years we are almost as concise as ancient abstype in ML :-)


Next inappropriate question for Scala: How to avoid the ubiquitious NPE 
problem of the JVM?


 	Makarius


More information about the isabelle-dev mailing list